Snippets of MySQL tips, solutions, examples, tutorials, and even benchmarks
Sunday, April 17, 2005
Problem in Mysql with equality comparison with float
There is a general problem when testing a floating point field for equality. The test (field=14.40) doesn't work because field is not exactly 14.40, but it could be 13.9999 or 14.0001. Use this test instead: (field between 13.9999 and 14.0001). Moreover, as a general rule, if you want precise results, don't use float, but decimal, and test by ranges (between y and z), instead of exact values (= x).