php.net |  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
Votes:3
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pjotrik at post dot cz
New email:
PHP Version: OS:

 

 [2008-01-16 15:13 UTC] pjotrik at post dot cz
Description:
------------
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:
---------------
$a=round(2.225,2);

Expected result:
----------------
$a=2.23

Actual result:
--------------
$a=2.22

Patches

Pull Requests

History

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] jani@php.net
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:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC