c# – Converting a string to a double – Education Career Blog

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?


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);

Leave a Comment