php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25694 round() and number_format() give inconsistent results.
Submitted: 2003-09-29 14:40 UTC Modified: 2003-11-17 21:48 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: russ at kdimail dot com Assigned:
Status: Closed Package: Math related
PHP Version: 4CVS, 5CVS OS: RedHat Linux 7.3
Private report: No CVE-ID:
 [2003-09-29 14:40 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-17 21:48 UTC] 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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 08:02:55 2014 UTC