In .net 4.0, web forms and IIS 8 I have in web.config this:
<globalization culture="pt-PT" uiCulture="pt-PT" />
When I do in C# this:
ltNumber.Text = (12345.12).ToString("N");
I get this: 12 345,12
But the output must be 12.345,12
This began to look bad on windows 10. windows 7 everything was fine. What can be wrong?
The numeric ("N"
) format specifier uses your CurrentCulture
settings.
That means your CurrentCulture
has white space as a NumberGroupSeparator
and ,
as a NumberDecimalSeparator
.
As a solution, you can Clone
your CurrentCulture
, set these properties what ever you want, and use that culture as a second parameter in your ToString
method. Like;
var clone = (CultureInfo) CultureInfo.CurrentCulture.Clone();
clone.NumberFormat.NumberDecimalSeparator = ",";
clone.NumberFormat.NumberGroupSeparator = ".";
ltNumber.Text = (12345.12).ToString("N", clone); // 12.345,12
I don't think these properties are changed based on operating system versions. It all about which culture settings you use.