2. SQL Data Types : Data Types : Floating Point Data Types : Float Point Limitations
 
Share this page                  
Float Point Limitations
You must consider the effects of data type conversions when numeric values are combined or compared. This is especially true when dealing with floating point values.
Exact matches on floating point numbers are discouraged, because float and float4 data types are approximate numeric values. In contrast, integer and decimal data types are exact numeric values.
Here is an example of why it is hard to find an exact match on a floating point number:
CREATE TABLE test(f8 FLOAT8);
INSERT INTO test VALUES(330/11.0);
SELECT * FROM test WHERE f8 = 30;
returns no rows.
On inspection,
SELECT HEX(f8) FROM test;
returns:
+----------------+
|col1            |
+----------------+
|403E000000000001|
+----------------+
Using an IEEE analyzer we find this number to be decimal 30.000000000000003552713678800500929355621337890625, which, though close to 30, shows why no exact match was found.
To ensure the query returns a row, you can change it to the following:
SELECT * FROM test WHERE ABS(f8 - 30) < 0.0000000001