Don't feel bad, many an experience programmer has been bitten by this.

The problem is that many decimal fractions do not have exact representations
as binary fractions. .01 is an example of this.

I'm not sure how MySQL does arithmetic internally, but (11.11 - 11) is just
a hair under .11:

mysql> SELECT (11.11 - 11) >= .10999999999999;
+---------------------------------+
| (11.11 - 11) >= .10999999999999 |
+---------------------------------+
|                               1 |
+---------------------------------+

You need to allow for a slight fudge factor. This is even a problem at the
hardware design level.

The best way to handle this is to make sure all of your operators are type
DECIMAL. You might have to cast them.

Apparently MySQL 5+ introduced some algorithms that helped with these
problems, although not with yours.


Regards,

Jerry Schwartz
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341

www.the-infoshop.com
www.giiexpress.com
www.etudes-marche.com

>-----Original Message-----
>From: Adam de Zoete [mailto:[EMAIL PROTECTED] On Behalf Of
>Adam de Zoete
>Sent: Thursday, May 15, 2008 7:24 AM
>To: mysql@lists.mysql.com
>Subject: Floor Decimal Math
>
>Hi,
>
>I'm running mysql 4.1.20 (Mac OS 10.4.11) and wondering why this ain't
>returning the right answer? Maybe i'm missing something or am i doing
>something wrong?
>
>mysql> select (11.11-FLOOR(11.11))>=0.11;
>+----------------------------+
>| (11.11-FLOOR(11.11))>=0.11 |
>+----------------------------+
>| 0                          |
>+----------------------------+
>
>Any help would be appreciated,
>
>Many thanks,
>
>Adam
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>infoshop.com





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to