0

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?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

4 Answers4

3

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);
Steve
  • 213,761
  • 22
  • 232
  • 286
  • Note that it will not work correctly with very large\very small numbers, because for them it will switch to scientific notation – Evk Oct 27 '17 at 11:15
1

The functionality of double.ToString() should to the magic:

double number = 1234.1234;
string s = number.ToString(CultureInfo.InvariantCulture);
M. Schena
  • 2,039
  • 1
  • 21
  • 29
0

This produces the required result:

Convert.ToString(12345.12345, System.Globalization.CultureInfo.InvariantCulture);
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
0

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
PinBack
  • 2,499
  • 12
  • 16