php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64543 Incorrect result of round
Submitted: 2013-03-28 16:28 UTC Modified: 2013-03-28 17:00 UTC
From: dev at medifirst dot fr Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.4.13 OS: Linux or Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dev at medifirst dot fr
New email:
PHP Version: OS:

 

 [2013-03-28 16:28 UTC] dev at medifirst dot fr
Description:
------------
The "round" function returns a bad value if "precision" > 17.


Test script:
---------------
php.ini
precision = 20



php -r "echo round(5.554, 2)"



Expected result:
----------------
5.55 is the expected value

Actual result:
--------------
5.5499999999999998224 is the incorrect result

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-28 17:00 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-03-28 17:00 UTC] nikic@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://www.floating-point-gui.de/

Thank you for your interest in PHP.

"precision" is the display precision. If you increase it you start seeing the rounding errors inherent to the floating point type.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 15:01:28 2025 UTC