Rounding

Rounding

am 13.10.2004 14:34:11 von Scott Simpson

------_=_NextPart_001_01C4B120.F1874B59
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Dear All,

=20

If I create a simple table with a single column of type FLOAT and I
insert 2 values say 5.8 and 5.9.

=20

When I issue 'SELECT * FROM t_table where f_float > 5.8, I get what I
expect.

=20

When I issue 'SELECT * FROM t_table where f_float < 5.9, I get what I
expect.

=20

When I issue 'SELECT * FROM t_table where f_float >=3D 5.8 I get what I
expect.

=20

When I issue 'SELECT * FROM t_table where f_float <=3D 5.9, I only get 1
row returned (i.e. 5.8 and not 5.9, which is not what I expect).

=20

Did I miss something?

=20

MySQL version 3.23.54.

=20

Regards,

Scott

=20

=20

=20

=20


------_=_NextPart_001_01C4B120.F1874B59--

Re: Rounding

am 13.10.2004 14:42:27 von Paul DuBois

At 13:34 +0100 10/13/04, Scott Simpson wrote:
>Dear All,
>
>
>
>If I create a simple table with a single column of type FLOAT and I
>insert 2 values say 5.8 and 5.9.
>
>
>
>When I issue 'SELECT * FROM t_table where f_float > 5.8, I get what I
>expect.
>
>
>
>When I issue 'SELECT * FROM t_table where f_float < 5.9, I get what I
>expect.
>
>
>
>When I issue 'SELECT * FROM t_table where f_float >= 5.8 I get what I
>expect.
>
>
>
>When I issue 'SELECT * FROM t_table where f_float <= 5.9, I only get 1
>row returned (i.e. 5.8 and not 5.9, which is not what I expect).
>
>
>
>Did I miss something?


http://dev.mysql.com/doc/mysql/en/Problems_with_float.html

--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Rounding

am 13.10.2004 15:07:30 von Jamie McCarthy

On Wed, 2004-10-13 at 08:34, Scott Simpson wrote:

> When I issue 'SELECT * FROM t_table where f_float <= 5.9, I only get 1
> row returned (i.e. 5.8 and not 5.9, which is not what I expect).

That's how floating-point numbers work. Integers, and other sums
of powers of two (like 1.5 or 5.75), can be represented exactly
in binary, given enough bits. But there is no way to exactly
represent the value 1/3 in binary floating point, with any finite
number of bits.

Same for 5.8 and 5.9. So these numbers are being stored
internally as slightly greater or less than the number you thought
you assigned. As a general principle, you should never expect an
equality operator (=, <=, >=) on a float to return true.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org