Friday, May 14, 2010

Issues with Floating Point Calculations in MySql

Regular comparisons over floating point numbers have some serious issues. The documentation states that DECIMAL type should be used for such comparisons, since they are stored as strings.

Floating point numbers are saved in a platform dependant format, and a simple value 9.78 , might not pass the test someVariable=9.78

The work around for such a problem is to use Round(someVariable,9.78)=9.78 ,for your code to work in the desired manner.

No comments:

Post a Comment