Convert.ToDouble uses the default CurrentCulture settings if you do not supply an IFormatProvider .
It looks like your CurrentCulture not using . like NumberDecimalSeparator , but it is probably used as NumberGroupSeparator . Therefore, your string was processed as 3400 not 3.4
As a solution, you can use a culture that already has . like NumberDecimalSeparator in the second parameter of your Convert.ToDouble method, for example InvariantCulture .
double x; x = Convert.ToDouble("3.47", CultureInfo.InvariantCulture);
For your -1.54 example -1.54 you need to specify to use the combined AllowLeadingSign and AllowDecimalPoint . Unfortunately, Convert.ToDouble does not have any overload, which takes NumberStyles as a parameter.
You can use the double.Parse method for double.Parse .
double x; x = double.Parse("-1.54", NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
source share