#24142 [Com]: round() does 5.045 to 5.04 instead of 5.05
| From: | php at oostende dot nl | Date: | Mon, 16 Feb 2004 18:56:42 +0000 |
| Subject: | #24142 [Com]: round() does 5.045 to 5.04 instead of 5.05 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-55021@lists.php.net to get a copy of this message | ||
ID: 24142
Comment by: php at oostende dot nl
Reported By: infohata at firmos dot net
Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 5.0.0-dev
Assigned To: stas
New Comment:
I have the same problem, wrote a testscript (in dutch, sorry, but I'm
sure you'll get the idea...) that does basic VAT calculation. Look at
http://www.tsrfietsplan.nl/rekentest.php
A small comment on the statement that rounding it this way saves money
on the long run: if I use this code for VAT calculation, I'll get lots
of credit notes and unhappy customers. Not good for business!
Previous Comments:
------------------------------------------------------------------------
[2003-08-09 11:16:13] iliaa@php.net
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2003-07-26 10:16:10] webmaster at ragnarokonline dot de
uhm, anyone?
------------------------------------------------------------------------
[2003-07-16 04:00:23] webmaster at ragnarokonline dot de
The test-case hasn't been corrected for PHP 4.3.3-dev
------------------------------------------------------------------------
[2003-06-16 14:16:12] sniper@php.net
Should always test myself and not trust others:
# /usr/src/web/php/php5/sapi/cli/php -n t.php
5.04499999999999992894573
5.04999999999999982236432
5.04999999999999982236432
5.05
No bug anywhere.
------------------------------------------------------------------------
[2003-06-16 14:00:55] sniper@php.net
With this script:
<?php
$mul = 1;
$one = 5;
$two = 0.9;
ini_set("precision", 24);
$res = 5 * (1 + (0.9 / 100));
$bar = round($res, 2);
$foo = round(1 * $bar, 2);
echo $res, "\n", $bar, "\n", $foo, "\n";
echo sprintf("%1.2f", $foo);
?>
Result with PHP 4.3.3-dev:
5.04499999999999992894573
5.04999999999999982236432
5.04999999999999982236432
5.05
Result with PHP 4.2.3:
5.04499999999999992894573
5.04000000000000003552714
5.04000000000000003552714
5.04
Nokia 6120 (the $res):
5.045
TI-32:
5.045
With pen and paper:
5.045
Round 5.045 with precision of 2 == 5.05
So I think PHP 4.3.2 actually works as expected
and anything before (and after, PHP 5? :) doesn't.
Reclassified as ZE2 bug.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/24142
--
Edit this bug report at http://bugs.php.net/?id=24142&edit=1