问题描述
我从XML文件中读取数字。其他的数字是用逗号分隔符(0,1111)等人用点(0.1111)。我如何分析这些数字,所以我得到最终想要的结果?我试着用 float.Parse(reader.Value,System.Globalization.CultureInfo.InvariantCulture);
,但它不工作。比如我有reader.Value =0,01119703,并解析为1119703.0。
I'm reading numbers from XML files. Other numbers are with a comma separator (0,1111) and others with dot (0.1111). How do I parse these numbers so I get the desired result in the end? I tried using float.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
but it doesn't work. For example I have reader.Value = "0,01119703" and is parsed as 1119703.0.
推荐答案
我不相信有可能在同一时间用两个不同的小数分隔工作。我想,我只想用替换()来更改任何逗号进入点。
I don't believe that it is possible to work with two different decimal separators at the same time. I think I would just use Replace() to change any commas into dots.
float.Parse(reader.Value.Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture);
这篇关于C#解析浮子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!