Double parse with culture format

Ryan picture Ryan · Feb 24, 2011 · Viewed 37.3k times · Source

I have a double number as string. The number is

202.667,40

Which is 202667.4

How can I parse this string to get the value like: Double.Parse("202.667,40",?what here), or any other method to get the value would be great. Thanks

Answer

Coincoin picture Coincoin · Feb 24, 2011

First, you need to know which culture this number is from, then:

CultureInfo culture = new CultureInfo("de"); // I'm assuming german here.
double number = Double.Parse("202.667,40", culture);

If you want to parse using the current thread culture, which by default is the one set for the current user:

double number = Double.Parse("202.667,40", CultureInfo.CurrentCulture);