1

Lets suppose this in C#.

  double d = 5.555455;
  string s = d.ToString();
  Console.WriteLine(s);

The output is

5.555455

In my case my regional configuration is for "." as decimal separator. The problem is that the computer's regional configuration sometimes is "," which makes the output to be:

5,555455

What I do need is to make sure that the number will be ALWAYS be converted to a string using "." as decimal and no "," as thousand separator.

How can I achieve this?

JK.
  • 21,477
  • 35
  • 135
  • 214
mdev
  • 472
  • 7
  • 18

1 Answers1

5

You need to use the invariant culture:

double d = 5.555455;
string s = d.ToString(CultureInfo.InvariantCulture);
Console.WriteLine(s);

Among other things, this forces the dot . as the decimal separator.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Thank you very much. The number is added to a JSON as number. It failed to parse when request comming from certain machnes. – mdev May 27 '14 at 03:38