views:

263

answers:

1

I'm trying to convert a string to a double value but it's not returning me what I expect...

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

That piece of code is returning 200.0 (instead of 20.0) as a double value. Any idea why?

+15  A: 

You should pass InvariantCulture to the method.

The reason behind this is that your regional settings probably set . as separator character and not decimal point.

double.TryParse("20.0", NumberStyles.Any, 
                CultureInfo.InvariantCulture, out x);
Mehrdad Afshari
Thanks, that solved it. :)
triton
this is very tricky
Ahmed Said