Re: Rounding
Jamie McCarthy <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <1097672850.15713.27.camel@ellie> |
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/[email protected]