Double.TryParse()输入十进制分隔符与系统小数分隔符不同 [英] Double.TryParse() input decimal separator different than system decimal separator

查看:136
本文介绍了Double.TryParse()输入十进制分隔符与系统小数分隔符不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源XML,它使用一个点(。)作为小数分隔符,我在使用逗号(,)作为小数分隔符的系统上进行解析。



因此,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆