2uzhan.com
Advertisement
Now Place:2uzhan.com » FLOAT data type and rounding

FLOAT data type and rounding

MySQL @ October 15, 2006   Views:0

Anyone can explain to me how floats are rounded in MySQL. For instance, I have a table declared as such:

create table zozo(FLOAT(12, 3) UNSIGNED); (MyISAM)

If I do the following:

insert into zozo(aaa) VALUES (999999997.0);
insert into zozo(aaa) VALUES (999999999.111);

Then:

select * from zozo;

I get:

+----------------+
| aaa |
+----------------+
| 1000000000.000 |
| 1000000000.000 |
+----------------+
2 rows in set (0.00 sec)

Am I missing something?

I'm on 5.0.15-nt on Windows

--------------Solutions-------------

This is a known side-effect of using IEEE format floating numbers.

See:
http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
http://docs.sun.com/source/806-3568/ncg_goldberg.html

If you need precise decimal numbers in MySQL, use DECIMAL or NUMERIC datatypes instead of FLOAT.

See:
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
http://dev.mysql.com/doc/refman/5.0/en/precision-math.html

Regards,
Bill K.

Tags:
© 2018 2uzhan.com Contact