MiguelM
MiguelM

Reputation: 197

Decimal point removed from decimals in a Serialized XML

I'm using XmlSerializer with classes created from a xsd using xsd.exe. It has worked fine for months.

Now I'm receiving reports that in some cases the created xml file has all decimals serialized without a decimal point, e.g. 123.45 is serialized as 12345.

I haven't been able to reproduce the problem, but I'm suspecting it may be related to localization.

This is my first C# project, so I may be overlooking something basic.

Could localization cause this problem?
How can I make the serialization process locale independent?

Any idea of something else that could cause this problem?

Upvotes: 2

Views: 1895

Answers (1)

C.Evenhuis
C.Evenhuis

Reputation: 26446

In some countries they use a comma as decimal separator, and the dot to separate thousands, so your hunch could be true. If you're using a float or another data type that holds decimals, XmlSerializer should not in any case throw away the decimals. However if in such a country you read The Xml without specifying a culture, it might ignore the dot.

So Xml serialized in one country and deserialized in another country would cause problems if you don't specify something like InvariantCulture.

Upvotes: 2

Related Questions