Double.TryParse()输入小数点分隔比系统小数点分隔不同 [英] Double.TryParse() input decimal separator different than system decimal separator
问题描述
我有一个使用一个点(。)作为小数点分隔源XML,我使用逗号(,)作为小数点分隔符的系统上分析这一点。
结果,0.7的值被解析与 Double.TryParse
或 Double.Parse
为700万
我的选择是正确解析?其中之一是与<code>与string.replace('',''),但我不认为我喜欢这个很喜欢。<替换源逗号点/ P>
XML标准是明确的关于日期和数字等的格式这有助于确保XML是平台无关的,可互操作。看看使用 XmlConvert XML数据。
双值= 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屋!