Format a decimal with Culture Info and thousand separators
Posted on 2009-04-04
I have a value in the database that is stored using the en-US culture info number formatting:
I want to display this value in my .Net C# web app using the user's CultureInfo.CurrentUICulture.NumberFormat, including the thousand separators. But I also do not want to truncate any of the decimal places.
So, if the user's Thread.CurrentThread.CurrentUICulture is set to "en-US", I want the number to show as:
If the user's Thread.CurrentThread.CurrentUICulture is set to "fr-BE", I want the number to show as:
I have only seen solutions that specify a certain number of decimal places, which would truncate my value. Right now I have the code as follows:
However, this doesn't insert the thousand separator as I want it to.
I also tried variations on:
return ((double)value).ToString("n", CultureInfo.CurrentUICulture.NumberFormat);
Which all insert the thousand separator, nut "n" truncates to 2 decimal places and any number (i.e. 0 or 2 or 10) after the "n" truncates the decimals or adds padding zeros.
Does anyone have a solution for this seemingly simple problem?
Thanks in advance!