Culture specific parsing of decimal numbers

Ever wanted to convert a decimal value that you know the format of without depending on what culture information the current app is running under? Well, here's how:
System.Globalization.NumberFormatInfo format = new System.Globalization.NumberFormatInfo();
format.NumberDecimalSeparator = "."; // this could be "," etc
format.NumberGroupSeparator = ",";
double d = Convert.ToDouble("9.95", format);
string s = d.ToString(f); // back to "9.95"

Related posts:

Comments

comments powered by Disqus