views:

239

answers:

2

Hi,

I have an application that runs on an English-US ASP.NET server (English installation of windows server and .NET Framework). I set the globalization settings to :

<globalization culture="auto" uiCulture="auto" responseEncoding="utf-8"/>

which works fine for most of the application. However, I have to deal with money transactions in that application and I need to provide the numbers in the 0.00 format (not 0,00). Most of our users use the application from a culture that uses 0,00.

I found out that even when using Decimal.ToString("0.00") the decimals were still being printed as 0,00 on french browsers.

What's the correct way of dealing with that issuue? Should I change the current culture for the function where I need to deal with numbers to set it to EN-US for the time being? Will I always get the right format if I use Decimal.ToString("0.00", NumberFormatInfo.InvariantInfo) ?

Thanks!

+1  A: 

Change culture on every variable is too painful. Try use the Thread culture info. Something like:

CultureInfo MyCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentCulture = MyCulture;

You may set this configuration at global.asax, at the user login or at master page level.

Best

Eduardo Xavier
It may also be the CurrentUICulture if CurrentCulture doesn't work.
GoodEnough
I actually wouldn't mind changing the culture on every variable as I only really need 4 of them to be in En-US culture. I don't really know how to set the culture on a variable though, how do you do that?
Hugo Migneron
I agree with jellomonkey. As I said, the solution still on the thread level... best!
Eduardo Xavier
+1  A: 

You can change most culture information by setting it. The specific setting you want is:

Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = "."
jellomonkey
Thanks, that's what I was looking for.
Hugo Migneron