开发者

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

开发者 https://www.devze.com 2023-01-25 07:34 出处:网络
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 stri

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

精彩评论

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