I am using XmlSerializer to serialize a C# object that contains a decimal to a string of xml
e.g.
AnObject.ADecimalValue
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
AnObject.ADecimalValue = decimal.Round(AnObject.ADecimalValue, 2);
The serializing code is below.
XmlSerializer serializer = new XmlSerializer(typeof(AnObject));
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, source);
string result = writer.ToString();
return result;
}
How can I ensure only two values are output out after the decimal point