Re: Round Function Error

Indrek Siitan <[email protected]>
Newsgroups gmane.comp.db.mysql.bugs
Message-ID <BBD81E11.36B9D%[email protected]>
Hi,

> I'm using mysql 4.0.16-standard on Linux.
> 
> I've just noticed this:
> 
> mysql> select round(0.5);
> +------------+
> | round(0.5) |
> +------------+
> |          0 |
> +------------+
> 1 row in set (0.00 sec)
> 
> --
> 
> mysql> select round(0.500001);
> +-----------------+
> | round(0.500001) |
> +-----------------+
> |               1 |
> +-----------------+
> 1 row in set (0.00 sec)
> 
> --
> 
> Is it not the case that 0.5 should be rounded UP?

MySQL uses the mathematical functions of the underlying operating systems
for these kinds of operations, so it depends on how OS has solved them.

In case of rounding, there are multiple possible standards defined on how to
round a number exactly half way between. Most of the operating systems,
including Linux, seem to use the one that tells to round to the nearest even
number, which in your case is 0.

To demostrate this:

  mysql> select round(3.5);
  +------------+
  | round(3.5) |
  +------------+
  |          4 |
  +------------+
  1 row in set (0.01 sec)

  mysql> select round(4.5);
  +------------+
  | round(4.5) |
  +------------+
  |          4 |
  +------------+
  1 row in set (0.00 sec)



Rgds,
Indrek

-- 
|  Indrek Siitan, MySQL AB, Support Engineer & Bugmaster
|  Uuemõisa, Haapsalu, Estonia
+- 
|  Are you MySQL Certified? http://www.mysql.com/certification/
--


-- 
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.