Bug #25694 [Com]: round() and number_format() give inconsistent results.
Edit report at http://bugs.php.net/bug.php?id=25694&edit=1
ID: 25694
Comment by: len at urmomshouse dot com
Reported by: russ at kdimail dot com
Summary: round() and number_format() give inconsistent results.
Status: Closed
Type: Bug
Package: Math related
Operating System: RedHat Linux 7.3
PHP Version: 4CVS, 5CVS
New Comment:
DUDE SHUT THE F*CK UP U NEWB
FAKE AND GAY
TR011!N 15 FUN
Previous Comments:
------------------------------------------------------------------------
[2003-11-17 21:48:58] 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-09-29 14:40:12] russ at kdimail dot com
Description:
------------
Round and number_format seem to be rounding the same numbers in
different ways, also the output of the "round" function does not match
the example given in the php documentation.
Round just seems to be always rounding up. Number format seems to be
rounding either up or down depending on the value of the number before
the decimal point.
In my php.ini I have changed precision = 14.
Reproduce code:
---------------
echo "round 0.045 = " . round(0.045, 2) . "<br>";
echo "number format 0.045 = " . number_format(0.045, 2) .
"<br><br>";
echo "round 0.055 = " . round(0.055, 2) . "<br>";
echo "number format 0.055 = " . number_format(0.055, 2) .
"<br><br>";
echo "round 5.045 = " . round(5.045, 2) . "<br>";
echo "number format 5.045 = " . number_format(5.045, 2) .
"<br><br>";
echo "round 5.055 = " . round(5.055, 2) . "<br>";
echo "number format 5.055 = " . number_format(5.055, 2) .
"<br><br>";
echo "round 3.025 = " . round(3.025, 2) . "<br>";
echo "number format 3.025 = " . number_format(3.025, 2) .
"<br><br>";
echo "round 4.025 = " . round(4.025, 2) . "<br>";
echo "number format 4.025 = " . number_format(4.025, 2) .
"<br><br>";
Actual result:
--------------
round 0.045 = 0.05
number format 0.045 = 0.05
round 0.055 = 0.06
number format 0.055 = 0.06
round 5.045 = 5.05
number format 5.045 = 5.04
round 5.055 = 5.06
number format 5.055 = 5.05
round 3.025 = 3.03
number format 3.025 = 3.02
round 4.025 = 4.03
number format 4.025 = 4.03
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=25694&edit=1
Thread (4 messages)