ID: 10313
Updated by: derick
Reported By: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: *Math Functions
PHP Version: 4.0.4pl1
Assigned To: 
Comments:

This isn't a bug. PHP uses the underlying C library to round, and all known C 
library's do this the same.
Actually, you are reporting a bug for MySQL, so please ask on there bug list for this.

Previous Comments:
---------------------------------------------------------------------------

[2001-04-12 22:20:44] [EMAIL PROTECTED]
Using MySQL 3.23.32 on RedHat Linux 7.0...

MySQL's ROUND function rounds 5 up when the preceding digit is odd and down when the 
preceding digit is even.

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

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

I think that this is technically the correct behavior, scientifically, anyway.  
However, this is not the common "lay-man's" method of rounding, which is to always 
round 5 up, as exhibited by PHP-4.0.4pl1...

        <? echo round(1.5); ?>
        <br>
        <? echo round(2.5); ?>

Apache 1.3.14 output for this is:

        2
        3

This discrepancy causes a difficulty in programming PHP and MySQL together, for 
example, because all of the rounding must be done in either PHP or MySQL but not both 
partially unless you want conflicting data.

I would like to see MySQL ROUND() syntax expand to be ROUND(X,D,M) where optional M 
value indicates the method of rounding, the default being the current method.

I would also like to see PHP round() syntax expand to be 
        double round (double val [, int precision] [, char method])
where the optional method value indicates the method of rounding, the default being 
the current method.

Thanks.

Lee Howard

---------------------------------------------------------------------------



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10313&edit=2


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to