In my app I parse a value from xml (string) to a double. The value in the xml happens to have the dot as a fraction seperator whereas the system takes the current system settings and can have a different separator (dev system takes the comma for example).
Is there a way to tell double.TryParse() the dot is the fraction separator?
Should I manually replace the dot with the system's fraction separator? If so, how do I get this?
-
Pass
CultureInfo.InvariantCulture
intodouble.TryParse
:double value; bool success = double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
(For genuinely standard XML formatting, Frederik's suggestion of using XmlConvert is the best idea though.)
-
What you should do, in this situation, is use the XmlConvert class and its members to convert the value like it exists in the XML file to a regular variable. :)
borisCallens : I didn't know such a thing existed. And why exactly is this class better then double.trypars()? I understand it can come in handy when there are special characters involved. But there is no tryparse as far as I can see.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.