Is decimal separator (‘.’ or ‘,’ ) depends of CurrentCulture?
I have a problem in serialization XML.
When I type ‘,’ as separator, I have an exception. (Culture is setted as DE-de)
Regards
example ( TestProperties is my own class for testing)
TestProperties properties = new TestProperties
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
double tempValue = 1.23 // Or 1,23
properties.DoubleValue = tempValue;
XmlSerializer serializer = new XmlSerializer(typeof(TestProperties));
TextWriter textWriter = new StreamWriter(XMLPath);
serializer.Serialize(textWriter, properties);
textWriter.Close();
public class TestProperties
{
private double _doubleValue;
[XmlElement("Double")]
public double DoubleValue
{
get { return _doubleValue; }
set { _doubleValue = value; }
}
}
It depends entirely on the context. You mention xml; within xml, the format is usually represented in a non-cultural culture (which means: . is decimal and , is thousands etc). Similarly, xml has specific representations for dates/times.
If you are building your xml via
XmlWriter,XElement,XmlSerializer(etc) this will be automatic; if you are building it by hand it could well be confused (a mix of different representations).If the data is not in the expected format, you might have to load it into a
stringproperty (rather than, say, afloatetc), and process it separately.