C# XML Serialization and Decimal Value

ISSI

New Member
I am using XmlSerializer to serialize a C# object that contains a decimal to a string of xmle.g. \[code\]AnObject.ADecimalValue\[/code\]I am finding the precision is varying in particular even if I explicitly round as below some values are getting output with four values after the point e.g. 12564.39 gets output as 12564.3900\[code\]AnObject.ADecimalValue = http://stackoverflow.com/questions/10330155/decimal.Round(AnObject.ADecimalValue, 2);\[/code\]The serializing code is below.\[code\] XmlSerializer serializer = new XmlSerializer(typeof(AnObject)); using (StringWriter writer = new StringWriter()) { serializer.Serialize(writer, source); string result = writer.ToString(); return result; }\[/code\]How can I ensure only two values are output out after the decimal point
 
Back
Top