Bug #52892 [Opn->Bgs]: Casting/rounding problem
| From: | rasmus@php.net | Date: | Mon, 20 Sep 2010 15:09:31 +0000 |
| Subject: | Bug #52892 [Opn->Bgs]: Casting/rounding problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154513@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52892&edit=1
ID: 52892
Updated by: rasmus@php.net
Reported by: vahe at spir dot me
Summary: Casting/rounding problem
-Status: Open
+Status: Bogus
Type: Bug
Package: *Math Functions
Operating System: Debian GNU/Linux 5.0.5 (lenny)
PHP Version: Irrelevant
Block user comment: 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://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
.
Previous Comments:
------------------------------------------------------------------------
[2010-09-20 13:25:34] vahe at spir dot me
Description:
------------
After adding 10 times 0.1 and casting it into int or flooring it return
value is 0
instead of 1.
Test script:
---------------
$a = 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1;
print $a; // 1
print round($a); // 1
print (int)$a; // 0 instead of 1
print floor($a); // 0 instead of 1
var_dump($a); // float(1)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52892&edit=1