Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about decimal separator

Tags:

c#

xml

separator

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; }
        }
    }
like image 537
GrzesiekO Avatar asked Jul 15 '26 10:07

GrzesiekO


1 Answers

Decimal separator is determined by the current culture, however, for XML Serialization, the current culture is not taken into account. XML convention will have to be used; decimal separator in XML will always be a point.

If you're building the XML by hand, you should use the XMLConvert class to make sure that all data-types are formatted correctly in the XML.

like image 187
Frederik Gheysels Avatar answered Jul 18 '26 01:07

Frederik Gheysels