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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 12:01:30 2024 UTC