Bug #64543 [Opn->Nab]: Incorrect result of round
Edit report at https://bugs.php.net/bug.php?id=64543&edit=1
ID: 64543
Updated by: nikic@php.net
Reported by: dev at medifirst dot fr
Summary: Incorrect result of round
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: Linux or Windows
PHP Version: 5.4.13
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-03-28 16:28:55] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64543&edit=1
Thread (2 messages)