Reputation: 171
I have a string with value "20.616378139" and when i try to convert using Convert.ToDouble or Double.Parse i get 20616378139.0 insted of the right value.
Why is this happening and how should I fix it?
Upvotes: 3
Views: 224
Reputation: 1
I've used this command and there is no problem for me before.
string s = "20.616378139"; double d = Convert.ToDouble(s); ![enter image description here][1]
Upvotes: -2
Reputation: 299
There's an overload to the Parse method that provides an options parameter of some kind; this is the way that you can specify for it to handle scientific notation, etc. Try setting that explicitly. If that works, then look at the default culture info settings you are using.
Upvotes: -2
Reputation: 941465
You probably live in a part of the world where the decimal point is written as a comma. Fix:
var str = "20.616378139";
var dbl = double.Parse(str, System.Globalization.CultureInfo.InvariantCulture);
Upvotes: 16