开发者

How to parse a number with a decimal regardless of the language setting

I am programming in C#.NET. I have a string that contains a number with a period as a decimal. How can I correctly parse that into a a double regardless of the localization/language settings. The string value will always be the same.

开发者_Go百科

I think I need to use the double.Parse(string s, IFormatProvider i) overload of parse but I don't understand how to use it.


For the IFormatProvider parameter, pass CultureInfo.InvariantCulture. It's in the System.Globalization namespace.


What about this...

CultureInfo ci = new CultureInfo("en-US");
myDouble= double.Parse("32.2", ci.NumberFormat);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜