When I write:
var d = 12.34D;
d.ToString();
it gives "12,34"
, but when I serialize object with double field, it gives "12.34"
It is because XmlSerializer
uses some specific format/culture? What exactly? I've looked into Double's source code but not seen implementation of IXmlSerializable
.
Thanks.
The XmlSerializerWriter
uses XmlConvert.ToString
to convert the values.
The relevant part from that class is this:
return value.ToString("R", NumberFormatInfo.InvariantInfo);
So it uses the invariant culture, which happens to output the string that is conforming to the XML RFC (So a period as decimal separator).
Format specifier "R"
is documented here:
The round-trip ("R") format specifier attempts to ensure that a numeric value that is converted to a string is parsed back into the same numeric value. This format is supported only for the Single, Double, and BigInteger types.
It means that the other end will produce the same double
result when deserializing the string value.