System.Convert.ToDouble
will use double.Parse
with the current culture by default. If your decimal separator is not .
you might get this exception.
The DateTime
thing is misleading since intellisense just tries to help you. Actually it's a number and not a DateTime
. So it's not your fault but the Visual-Studio team could improve this message. The FormatException
's Message
property does not contain DateTime
.
It sounds like you want the invariant culture:
double d = double.Parse("0.0005", CultureInfo.InvariantCulture);
If you're not sure if the format is valid you should use double.TryParse
:
double d;
if (double.TryParse("0.0005", NumberStyles.Any, CultureInfo.InvariantCulture, out d))
{
Console.Write("Value is: " + d);
};