MySQL floating point comparison issues

Posted by Sharief on Stack Overflow See other posts from Stack Overflow or by Sharief
Published on 2010-04-02T15:22:28Z Indexed on 2010/04/02 15:33 UTC
Read the original article Hit count: 273

I ran into an issue by introducing floating point columns in the MySQL database schema that the comparisons on floating point values don't return the correct results always.

1 - 50.12
2 - 34.57
3 - 12.75
4 - ...(rest all less than 12.00)

SELECT COUNT(*) FROM `users` WHERE `points` > "12.75"

This returns me "3".

I have read that the comparisons of floating point values in MySQL is a bad idea and decimal type is the better option.

Do I have any hope of moving ahead with the float type and get the comparisons to work correctly?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query