Convert string to double

I am trying to convert a string to a double value, but that does not return to me what I expect ...

double dbl;
Double.TryParse("20.0", out dbl);

This piece of code returns 200.0 (instead of 20.0) as a double value. Any idea why?

+5
source share
1 answer

You must pass to the InvariantCulturemethod.

The reason for this is because your regional settings are probably set .as a delimiter, not a decimal point.

double.TryParse("20.0", NumberStyles.Any, 
                CultureInfo.InvariantCulture, out x);
+22
source

All Articles