I have a project where a user can enter a decimal in a textbox. Now I take that value and tryparse it into a nullable float variable, which I pass to a tableAdapter to Insert or Update the DB.
Now here is where it gets wierd, if I give it a value of .24, that is what gets passed to the tableAdapter, however, when I look at what is saved to the database, it is transformed into 0.239999994635582.
I debuged it up to the insert call of the TableAdapter, and it is being passed a value of .24. My SQL server database column has a type of float.
Any idea on why this could be happening? Do I need to switch to decimal?
Thanks
The solution is the internal power of 2 representation of
float numbers.
Some fractional values cannot be represented very well.
Read more here: IEEE 754 Floating point numbers
Switching to decimal will work here, but also has impact to the performance.
(somewhat 10 times slower than float, but you probably will never notice it)