2

I'm parsing a xml file containing strings like "91.899,74" (which is the correct format in my country) which I would like to convert into a float using float.Parse() but I can't get it to work without replacing "." with "" and "," with "."

If I don't do the replacements I get input was not in the correct format exception.

Any ideas on how to do the convert ?

user1005448
  • 617
  • 3
  • 12
  • 22

1 Answers1

4

You need to use your culture settings:

CultureInfo culture = new CultureInfo("de");
double number = Double.Parse("202.667,40", culture);

float.Parse() doesn't work the way I wanted

Double parse with culture format

Community
  • 1
  • 1
Stephen King
  • 816
  • 4
  • 14