Double.TryParse()输入十进制分隔符与系统小数分隔符不同 [英] Double.TryParse() input decimal separator different than system decimal separator
问题描述
因此,0.7的值将被解析为 Double.TryParse
或 Double。解析
为7000000。
我有什么选择正确解析?其中一个是使用 String.Replace('。',',')
以逗号替换源代码点,但我不认为我非常喜欢这个。 / p>
XML标准对于日期和数字的格式等是明确的。这有助于确保XML是平台无关的和可互操作的。使用 XmlConvert 查看xml数据。 / p>
double value = XmlConvert.ToDouble(stringValue);
I have a source XML that uses a dot (".") as a decimal separator and I am parsing this on a system that uses a comma (",") as a decimal separator.
As a result, value of 0.7 gets parsed with Double.TryParse
or Double.Parse
as 7000000.
What are my options to parse correctly? One of them is to replace dots in source with commas with String.Replace('.', ',')
but I don't think I like this very much.
XML standard is explicit about the formatting of dates and numbers etc. This helps to ensure that the XML is platform independent and interoperable. Take a look at using XmlConvert for xml data.
double value = XmlConvert.ToDouble(stringValue);
这篇关于Double.TryParse()输入十进制分隔符与系统小数分隔符不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!