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);
精彩评论