From:             russ at kdimail dot com
Operating system: RedHat Linux 7.3
PHP version:      4.3.3
PHP Bug Type:     *Math Functions
Bug description:  Round and number_format give inconsistent results.

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 bug report at http://bugs.php.net/?id=25694&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25694&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25694&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25694&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25694&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25694&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25694&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25694&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25694&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25694&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25694&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25694&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25694&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25694&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25694&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25694&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25694&r=float

Reply via email to