May be this is a very basic question, but I am really interested to know what really happens.
For example if we do the following in c#:
object obj = "330.1500249000119";
var val = Convert.ToDouble(obj);
The val becomes: 330.15002490001189
The question is that why the last 9 is replace by 89? Can we stop it from happening this way? And is this precision dependent on the Current Culture?
This has nothing to do with culture. Some numbers can not be exactly represented by a base-2 number, just like in base-10 1/3rd can’t be exactly represented by .3333333
Note that in your specific case you are putting in more digits than the data type allows: the significant digits available with a Double is 15-16 (depending on range), which your number goes beyond.
Instead of a
Double, you can use aDecimalin this case: