Reputation: 2132
Convert.ToDouble Method (String) converts the specified String representation of a number to an equivalent double-precision floating point number.
I have this line of code: double d = Convert.ToDouble("0.3");
and it gives me 3.0 instead of 0.3. For numbers greater than 1 it works as expected. Why?
Upvotes: 0
Views: 1453
Reputation: 4180
What are the current Culture settings? It's probably because in the culture settings you are using the '.' is not the decimal delimiter!
Upvotes: 0
Reputation: 160962
Try this:
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
double d = Convert.ToDouble("0.3", provider);
Upvotes: 1
Reputation: 108830
Most likely a locale problem. There are cultures where .
is not the decimal separator.
Try double.Parse("0.3",CultureInfo.InvariantCulture)
Upvotes: 6