You have an international application that must always display currency with the U.S. dollar symbol but all other text must follow the language setting in the browser.
Implement the solution described in Recipe 14.2, and then use a
CultureInfo
object to override the default
currency format of the currency value in the code-behind class for
the page, as shown here:
litCost.Text = sampleValue.ToString("C", _ New CultureInfo("en-US")) litCost.Text = sampleValue.ToString("C", new CultureInfo("en-US"));
It is not uncommon to have an international application that needs to display dates, a currency value, or other data in a format specific to a language or culture that is not the default. For example, you might need to display currency values in U.S. format but all text and dates in the local language of the user.
The simplest solution in such cases is to implement the example
described in Recipe 14.2 and then use the
ToString
method of the number to override its
default currency setting. Use the "C
" string
format code to indicate the number should be formatted as a currency
value and a CultureInfo
object to require U.S.
English with the en-US
language code. If you have
many places where the alternate currency formatting is required, you
should implement a single method to perform it. This will make
changes much simpler when they are required.
If your application does not need to display non-currency values such
as dates or other numbers in the user’s local
language format, an even simpler solution is to leave the
CurrentCulture
property of the current thread
unset. This way all formatting of dates and numbers will follow the
regional settings of your web server without any additional coding.