Bug #54184 [Opn->Bgs]: (int)(1.13*100) returns 112 !!!!! (should be 113)
Edit report at http://bugs.php.net/bug.php?id=54184&edit=1
ID: 54184
Updated by: derick@php.net
Reported by: yuriy at vihv dot org
Summary: (int)(1.13*100) returns 112 !!!!! (should be 113)
-Status: Open
+Status: Bogus
Type: Bug
Package: Unknown/Other Function
Operating System: Linux 2.6.33.3-85.fc13
PHP Version: 5.3.5
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.
.
Previous Comments:
------------------------------------------------------------------------
[2011-03-07 16:56:13] yuriy at vihv dot org
Description:
------------
Sample code below returns 112 instead of 113. echo (int)(113); and echo
1.13*100;
works just fine.
Other numbers like 2.13, 1.14 works fine
Well, in fact i use php 5.3.3. No i wont upgrade. I've post some bug a
few years
ago and still get no response. So i post it here just in case. Go ahead,
mark it
as "could not reproduce" and go get one more cup of coffee... Or you can
really
check it, bug looks a bit ugly.
Test script:
---------------
<?php
echo (int)(1.13*100);
?>
Expected result:
----------------
113
Actual result:
--------------
112
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54184&edit=1
Thread (2 messages)