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

 ID:               51233
 Updated by:       [email protected]
 Reported by:      daniel dot seif at castex dot de
 Summary:          Wrong results with float arithmetics
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Multiple
 PHP Version:      5.3.2

 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-03-08 11:57:15] daniel dot seif at castex dot de

Description:
------------
When calculating with and rounding float values, the result of the
calculation is wrong.



This bug seems to affect multiple versions of php. I have tested it with
PHP 5.3.2 (Fedora 12), PHP 5.2.6 (Red Hat), PHP 5.3.0 (Windows XP).

Test script:
---------------
echo floor(138.95 * 100), "\n";

echo floor(141.95 * 100), "\n";

echo floor(142.95 * 100), "\n";



echo intval(142.95 * 100), "\n";

echo (int)(138.95 * 100);

Expected result:
----------------
13895

14195

14295

14295

13895

Actual result:
--------------
13894

14194

14294

14294

13894


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



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

Reply via email to