#25694 [Opn->Ver]: Round and number_format give inconsistent results.
ID: 25694
Updated by: sniper@php.net
Reported By: russ at kdimail dot com
-Status: Open
+Status: Verified
-Bug Type: *Math Functions
+Bug Type: Math related
Operating System: RedHat Linux 7.3
-PHP Version: 4.3.3
+PHP Version: 4CVS, 5CVS
Previous Comments:
------------------------------------------------------------------------
[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/?id=25694&edit=1
Thread (4 messages)