List:General Discussion« Previous MessageNext Message »
From:iConnect \(Berlin\) Stefan Hinz Date:January 20 2003 9:42pm
Subject:Re: Is it normal?
View as plain text  
Octavian,

> mysql> create table test(id float);
> mysql> insert into test values(1.123), (3.1495);
> mysql> select * from test where id=1.123;
> Empty set (0.00 sec)
> Shouldn't this last query show me the record that has the id=1.123?

Well ... 1.123 is greater than 1.123, see:

mysql> select id from octavian where id > 1.123;
+--------+
| id     |
+--------+
|  1.123 |
| 3.1495 |
+--------+
2 rows in set (0.00 sec)

Now here's why. Floats are simply not precise:

mysql> select id*10000 from octavian where id > 1.123;
+-----------------+
| id*10000        |
+-----------------+
| 11230.000257492 | <----------
| 31494.998931885 |
+-----------------+
2 rows in set (0.00 sec)

> What query should I use to do this?

I leave this one to Paul or one of the other gurus.

Regards,
--
  Stefan Hinz <hinz@stripped>
  Geschäftsführer / CEO iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Tel: +49 30 7970948-0  Fax: +49 30 7970948-3

----- Original Message -----
From: "Octavian Rasnita" <orasnita@stripped>
To: "MySQL" <mysql@stripped>
Sent: Monday, January 20, 2003 9:34 AM
Subject: Is it normal?


> Hi all,
>
> I've tried the following SQL queries:
>
> mysql> create table test(id float);
> Query OK, 0 rows affected (0.00 sec)
>
> mysql> insert into test values(1.123), (3.1495);
> Query OK, 2 rows affected (0.01 sec)
> Records: 2  Duplicates: 0  Warnings: 0
>
> mysql> select * from test where id=1.123;
> Empty set (0.00 sec)
>
> Shouldn't this last query show me the record that has the id=1.123?
>
> What query should I use to do this?
>
> Thank you.
>
>
>
> Teddy,
> Teddy's Center: http://teddy.fcc.ro/
> Email: orasnita@stripped
>
>
>
> ---------------------------------------------------------------------
> 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 <mysql-thread130430@stripped>
> To unsubscribe, e-mail
<mysql-unsubscribe-list_hinz=iconnect.de@stripped>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>

Thread
Is it normal?Octavian Rasnita20 Jan
  • Re: Is it normal?Dobromir Velev20 Jan
  • Re: Is it normal?iConnect \(Berlin\) Stefan Hinz20 Jan
  • Re: Is it normal?Octavian Rasnita24 Jan
  • Re: Is it normal?gerald_clark24 Jan
  • Re: Is it normal?Octavian Rasnita25 Jan
    • Re: Is it normal?Paul DuBois26 Jan