|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43867 Invalid round() function output
Submitted: 2008-01-16 15:13 UTC Modified: 2008-01-26 00:58 UTC
Avg. Score:4.7 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: pjotrik at post dot cz Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.2.5 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2008-01-16 15:13 UTC] pjotrik at post dot cz
When I try to round a number like X.YZ5 with precision 2, I get X.YZ, but Z number should be incremented to Z+1

Reproduce code:

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-16 15:46 UTC] pjotrik at post dot cz
Sorry, I have a better example:

echo (4.3*((100-25)/100));
    ----> result: 3.225

echo round(4.3*((100-25)/100),2);
    ----> result: 3.22

echo round(3.225,2);
    ----> result: 3.23
 [2008-01-26 00:58 UTC]
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
Thank you for your interest in PHP.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 09:01:30 2024 UTC