I need to convert double to string with two decimal digits separated with 'dot' My concern is that dot must be always used as separator.
Asked
Active
Viewed 2,831 times
2 Answers
13
The simplest way is to specify CultureInfo.InvariantCulture
as the culture, e.g.
string text = d.ToString("N2", CultureInfo.InvariantCulture);

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
Jon, does CultureInfo.InvariantCulture assume 'dot'? – Captain Comic Oct 19 '10 at 17:55
-
2@Captain Comic: Yes. For *most* purposes, you can think of the invariant culture as being pretty much US English :) – Jon Skeet Oct 19 '10 at 18:19
1
Perhaps to avoid messing up with CultureInfo settings on clients systems, we better set a concrete way to force the machine to use dot as decimal separator and not thousand separator ==> regardless of culture! So,
NumberFormatInfo fi= new NumberFormatInfo();
fi.NumberDecimalSeparator = ".";
string doubleDotDecimalNr = doubleNr.ToString(fi);

Ali Safari
- 1,535
- 10
- 19