Language invariant Double.ToString()
Use:
string networkMsg = "command " + value.ToString(CultureInfo.InvariantCulture);
or:
string networkMsg = string.Format(CultureInfo.InvariantCulture, "command {0}", value);
This needs using System.Globalization;
in the top of your file.
Note: If you need full precision, so that you can restore the exact double again, use the Format
solution with the roundtrip format {0:R}
, instead of just {0}
. You can use other format strings, for example {0:N4}
will insert thousands separators and round to four dicimals (four digits after the decimal point).
Since C# 6.0 (2015), you can now use:
string networkMsg = FormattableString.Invariant($"command {value}");
Specify the invariant culture as the format provider:
value.ToString(CultureInfo.InvariantCulture);
The .
in the format specifier "0.0"
doesn't actually mean "dot" - it means "decimal separator" - which is ,
in France and several other European cultures. You probably want:
value.ToString(CultureInfo.InvariantCulture)
or
value.ToString("0.0", CultureInfo.InvariantCulture)
For info, you can see this (and many other things) by inspecting the fr culture:
var decimalSeparator = CultureInfo.GetCultureInfo("fr")
.NumberFormat.NumberDecimalSeparator;