Reputation: 3773
How can I serialize / deserialize a double value so that it can be read and written on systems with different decimal point symbols?
Write:
double d; d.ToString();
Read:
double d = (double)Convert.ChangeType(serialized_value, new Double().GetType());
Upvotes: 3
Views: 1421
Reputation: 3383
You have to specify an invariant format provider
double d = 2.0;
var invariantString = Convert.ToString(d, CultureInfo.InvariantCulture);
var d2 = Convert.ToDouble(invariantString, CultureInfo.InvariantCulture);
Upvotes: 2