ID:               33731
 User updated by:  peebrain at psipog dot net
 Reported By:      peebrain at psipog dot net
 Status:           Bogus
 Bug Type:         Math related
 Operating System: Linux
 PHP Version:      4.3.11
 New Comment:

Sorry, I mean... shouldn't the SECOND echo produce 229.9999999 ?


Previous Comments:
------------------------------------------------------------------------

[2005-07-17 17:59:31] peebrain at psipog dot net

Shouldn't the third echo produce 229.999999999 then, instead of 230?

------------------------------------------------------------------------

[2005-07-17 07:48:58] [EMAIL PROTECTED]

This is not a bug.  Computers have no way to represent floating point
numbers accurately.  They can only approximate them to a certain
precision.  Whenever you do anything that requires absolute precision,
you need to take this into account.  2.3*100 is never going to be
exactly 230.  It's going to be 229.99999999999999999 or
230.0000000000000001 and if you do (int)229.99999999999999999 you are
going to get 229.

------------------------------------------------------------------------

[2005-07-17 07:36:10] peebrain at psipog dot net

Description:
------------
When rounding with int casting, it seems to screw it up on this weird
case.  If you cast 230 to int, it will change to 229 in this one case.

Reproduce code:
---------------
$r = 2.3;
echo $r."<BR>";
$r = $r * 100.0;
echo $r."<BR>";
$r = (int)$r;
echo $r."<BR>";
$r = $r / 100.0;
echo $r;

Expected result:
----------------
2.3
230
230
2.3

Actual result:
--------------
2.3
230
229
2.29 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33731&edit=1

Reply via email to