Floating-point Accuracy
Explanation of floating-point precision issues. This page details why FLOAT and DOUBLE types are approximate and how rounding errors occur.
Example
CREATE TABLE fpn (id INT, f1 FLOAT, f2 DOUBLE, f3 DECIMAL (10,3));
INSERT INTO fpn VALUES (1,2,2,2),(2,0.1,0.1,0.1);
SELECT * FROM fpn WHERE f1*f1 = f2*f2;
+------+------+------+-------+
| id | f1 | f2 | f3 |
+------+------+------+-------+
| 1 | 2 | 2 | 2.000 |
+------+------+------+-------+SELECT f1*f1, f2*f2, f3*f3 FROM fpn;
+----------------------+----------------------+----------+
| f1*f1 | f2*f2 | f3*f3 |
+----------------------+----------------------+----------+
| 4 | 4 | 4.000000 |
| 0.010000000298023226 | 0.010000000000000002 | 0.010000 |
+----------------------+----------------------+----------+Last updated
Was this helpful?

