I know that it is a bad idea to store decimal values as float in mysql.
Example: If I store a product the price of $ 5.01, there is no exact floating type representation of that number.
If I you do that:
CREATE TABLE IF NOT EXISTS `test` (
`test` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `test` (`test`) VALUES
(5.01);
and then you run the query
SELECT AVG( test )
FROM test
against that table you will end up with this:
mysql> select avg(test) from test;
+------------------+
| avg(test) |
+------------------+
| 5.01000022888184 |
+------------------+
1 row in set (0.00 sec)
however if you select just the field like this:
mysql> select * from test;
+------+
| test |
+------+
| 5.01 |
+------+
1 row in set (0.00 sec)
you end up with the correct amount.
My question is: How can that be?
If float type cannot represent my value accurately?
Shouldnt the select return 5.01000022888184 as well?