Bug #61624 [Opn->Nab]: round
| From: | aharvey@php.net | Date: | Thu, 05 Apr 2012 13:49:24 +0000 |
| Subject: | Bug #61624 [Opn->Nab]: round | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169265@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61624&edit=1
ID: 61624
Updated by: aharvey@php.net
Reported by: gufophp at gmail dot com
Summary: round
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: win32
PHP Version: 5.4.0
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.
The return value of round() is still a floating point number. If the precision is
high enough, printing that float may result in seeing additional significant
digits because of the imprecision inherent to floating point arithmetic.
Previous Comments:
------------------------------------------------------------------------
[2012-04-05 13:08:07] gufophp at gmail dot com
php.ini
change precision to
precision = 17
------------------------------------------------------------------------
[2012-04-05 03:05:37] reeze dot xia at gmail dot com
Hi, gufophp:
I can't reproduce it in both 5.4 & 5.3 | Win7 & Mac OS X. can you feedback more
information about this?.
Thanks
------------------------------------------------------------------------
[2012-04-04 17:06:35] gufophp at gmail dot com
Description:
------------
<?php
echo round(33.29999999999999715783,4); // fail
echo "-";
echo round(33.29999999999999715783,2); // fail
echo "-";
echo round(33.29999999999999715783); //ok
echo "-";
echo round(33.29999999999999715783,-1); //ok
echo "-";
echo round(55533.29999999999999715783,-2); //ok
?>
Test script:
---------------
33.29999999999999715783-33.29999999999999715783-33-30-55500
Expected result:
----------------
33.3-33.3-33-30-55500
Actual result:
--------------
33.29999999999999715783-33.29999999999999715783-33-30-55500
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61624&edit=1