MySQL manual A.5.7  Problems with floating point comparison

=dn



----- Original Message ----- 
From: "Gerald Clark" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: 08 February 2002 15:24
Subject: Re: Problems with select


> 15.8 has no exact binary representation, so a test for  equality will fail.
> Do not use floating point if you want to test for equality. Try DECIMAL
> 
> Miguel Figueiredo wrote:
> 
> >Hello all,
> >
> >I have a (probably dumb) question. 
> >My table "temperatura" has two fields described bellow.
> >
> >mysql> describe temperatura;
> >+-------------+----------+------+-----+---------+-------+
> >| Field            | Type     | Null | Key | Default | Extra |
> >+-------------+----------+------+-----+---------+-------+
> >| datetime      | datetime | YES  |     | NULL    |       |
> >| temperatura | float    | YES  |     | NULL    |       |
> >+-------------+----------+------+-----+---------+-------+
> >2 rows in set (0.00 sec)
> >
> >
> >When I try to select rows with floats, the result is an empty set.
> >For example:
> >
> >mysql> select datetime,temperatura from temperatura where 
> >datetime="2002-02-08 09:30:00";
> >+---------------------+-------------+
> >| datetime            | temperatura |
> >+---------------------+-------------+
> >| 2002-02-08 09:30:00 |        15.8 |
> >+---------------------+-------------+
> >1 row in set (0.00 sec)
> >
> >----------------------------> got one row :)
> >
> >mysql>select datetime,temperatura from temperatura where datetime="2002-02-08 
> >09:30:00" and temperatura=15.8;
> >
> >Empty set (0.00 sec)
> >
> >----------> same thing but with the temperatura value, gives me an empy set :(
> >
> >When I try to select another row but the temperatura field has an integer 
> >this is what happens:
> >
> >mysql> select datetime,temperatura from temperatura where 
> >datetime="2002-01-25 09:40:00";
> >+---------------------+-------------+
> >| datetime            | temperatura |
> >+---------------------+-------------+
> >| 2002-01-25 09:40:00 |          16 |
> >+---------------------+-------------+
> >1 row in set (0.00 sec)
> >
> >-----------> got one row :)
> >
> >mysql> select datetime,temperatura from temperatura where 
> >datetime="2002-01-25 09:40:00" and temperatura=16;
> >+---------------------+-------------+
> >| datetime            | temperatura |
> >+---------------------+-------------+
> >| 2002-01-25 09:40:00 |          16 |
> >+---------------------+-------------+
> >1 row in set (0.00 sec)
> >
> >--------------> It works now :/
> >
> >Does anyone have an idea why this happens? How can I select float numbers?
> >
> >Best wishes,
> >
> >Miguel
> >
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to