views:

296

answers:

2

<%#String.Format("{0:c}", Eval("Subtotal"))%>

I am doing that but if the language is Spanish, this is being displayed 475,00 €

The client wants it so that it is actually $ 475.00

possible?

+1  A: 

You will need to create a CultureInfo that uses "$" as the currency symbol, then pass it as the first parameter to String.Format.

John Saunders
NumberFormatInfo.CurrentInfo.CurrencySymbol = "$"; which changes the symbol but it appends it to the end? instead of $ 475.
TimLeung
+1  A: 

The string is formatted according to the CurrentUICulture. You can specify the culture explicitly by passing a CultureInfo to Format, for example US English:

<%#String.Format(CultureInfo.GetCultureInfo("en-US"), "{0:c}", Eval("Subtotal"))%>

To set the culture globally so you don't have to specify it each time, you can change the CurrentUICulture:

Thread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US")
dtb
I like this approach, but the first approach of setting the format in one place minimizes changes right now. Is there something that can be done in one place? Secondly, I tried copying the code directly...it doesn't understand CultureInfo..am I missing something?
TimLeung
CultureInfo is in the System.Globalization namespace which you probably need to import. See my edited answer regarding change in one place.
dtb