Bug #43561 | can't find some floating point numbers | ||
---|---|---|---|
Submitted: | 11 Mar 2009 13:05 | Modified: | 11 Mar 2009 14:20 |
Reporter: | Mario Dejung | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: General | Severity: | S3 (Non-critical) |
Version: | 5.0.70 | OS: | Linux |
Assigned to: | CPU Architecture: | Any | |
Tags: | <=, =, between, FLOAT |
[11 Mar 2009 13:05]
Mario Dejung
[11 Mar 2009 14:14]
Valeriy Kravchuk
Sorry, but this is expected and documented behavior. Please, read the manual, http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html. Look: valeriy-kravchuks-macbook-pro:5.0 openxs$ bin/mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.80-debug Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table test (test FLOAT NOT NULL); Query OK, 0 rows affected (0.00 sec) mysql> insert into test values (2),(2.1),(2.2),(2.21),(2.22),(2.23),(2.24),(2.25),(2.26); Query OK, 9 rows affected (0.01 sec) Records: 9 Duplicates: 0 Warnings: 0 mysql> select * from test where test=2.2; Empty set (0.00 sec) mysql> select * from test where test<2.3; +------+ | test | +------+ | 2 | | 2.1 | | 2.2 | | 2.21 | | 2.22 | | 2.23 | | 2.24 | | 2.25 | | 2.26 | +------+ 9 rows in set (0.00 sec) mysql> select 2.2*1000000, test*1000000 from test where test < 2.21; +-------------+------------------+ | 2.2*1000000 | test*1000000 | +-------------+------------------+ | 2200000.0 | 2000000 | | 2200000.0 | 2099999.90463257 | | 2200000.0 | 2200000.04768372 | +-------------+------------------+ 3 rows in set (0.00 sec) So, 2.2 is NOT stored exactly as 2.2 in FLOAT column.
[11 Mar 2009 14:20]
Mario Dejung
Thanks, I figured it out just one second ago. I changed my values to DECIMAL, now everything works fine.