double temp;
temp = (double)Convert.ToDouble(\"1234.5678\");
Hey Lads and Ladies, I can\'t for the life of me figure out why the above line isn\'t
Check your regional settings. Your decimal symbol needs to be ".".
You may be somehow using a european local. In some countries the . and , in numbers is reversed.
Hi as Mario says you must parse it taking into account the regional settings.
double temp = double.Parse("1234.5678", System.Globalization.CultureInfo.CurrentCulture);
Regards.
I recommend you use TryParse
instead, so you don't need to handle parsing exceptions.
double temp = 0;
if (double.TryParse("123.456", out temp)
{
Console.WriteLine(string.Format("Parsed temp: {0}", temp);
}
else
{
Console.WriteLine("Input value was not able to be parsed.");
}