When I do 12345.12345 + ""
I get "12345,12345"
on my windows machine's IIS Express.
I need to convert the number to the standard representation that can be parsed by other programs, that is XXXX.XXXX
- no spaces, no commas. How to do that?
When I do 12345.12345 + ""
I get "12345,12345"
on my windows machine's IIS Express.
I need to convert the number to the standard representation that can be parsed by other programs, that is XXXX.XXXX
- no spaces, no commas. How to do that?
The Convert.ToString method has an overload that allows a second parameter to be the CultureInfo used to create the string representation of your number. CultureInfo.InvariantCulture is the static class that contains the . as decimal separator. Putting all together your get
string myString = Convert.ToString(12345.12345, CultureInfo.InvariantCulture);
The functionality of double.ToString()
should to the magic:
double number = 1234.1234;
string s = number.ToString(CultureInfo.InvariantCulture);
This produces the required result:
Convert.ToString(12345.12345, System.Globalization.CultureInfo.InvariantCulture);
Maybe you can set the culture for your thread:
string lsOut = (1234.1234 + "").ToString();
Console.WriteLine(lsOut);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.LCID);
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator = "";
lsOut = (1234.1234 + "").ToString();
Console.WriteLine(lsOut);
Output is (If de-DE
is set first):
1234,1234
1234.1234