#40622 [Opn->Bgs]: round function
| From: | johannes@php.net | Date: | Sat, 24 Feb 2007 22:05:52 +0000 |
| Subject: | #40622 [Opn->Bgs]: round function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-109480@lists.php.net to get a copy of this message | ||
ID: 40622
Updated by: johannes@php.net
Reported By: bruno dot boccara at d2b dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: windows 2003 Apache 2
PHP Version: 4.4.5
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://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
.
Previous Comments:
------------------------------------------------------------------------
[2007-02-24 21:36:47] bruno dot boccara at d2b dot com
Description:
------------
round function gives wrong value.
Please do not send me to
http://docs.sun.com/source/806-3568/ncg_goldberg.html,
you have to
admit that this is a bug !!!!!
if not, php CANNOT be use in production site with mathematical
functions !!!
Reproduce code:
---------------
<?
// 140.25*(1-(34/100)) = 92.565
echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>";
echo "direct = ".round (92.565, 2);echo "<br>";
$valeur = 140.25*(1-(34/100));
echo "value = ".round($valeur,2);echo "<br>";
settype($valeur,"string");
settype($valeur,"float");
echo "value2 = ".round($valeur,2);
?>
Expected result:
----------------
formula = 92.57
direct = 92.57
value = 92.57
value2 = 92.57
Actual result:
--------------
formula = 92.56 // WRONG !
direct = 92.57
value = 92.56 // WRONG !
value2 = 92.57
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40622&edit=1