ID: 47449 Updated by: der...@php.net Reported By: office at devstudio dot ro -Status: Open +Status: Bogus Bug Type: Feature/Change Request Operating System: Windows, FreeBSD, Linux PHP Version: 5.2.9RC2 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: ------------------------------------------------------------------------ [2009-02-19 11:22:08] office at devstudio dot ro Description: ------------ Mathenatical comparison of an expression with it's result returns false When I try to compare 1.5 * 0.19 with it's result, 0.285, PHP returns false, but when i display the result 1.5 * 0.19 it echoes 0.285. Reproduce code: --------------- <?php // BUG!!! This expression should return TRUE, because 1.5 * 0.19 is 0.285 echo ((1.5 * 0.19) == 0.285) ? "TRUE" : "FALSE"; echo "<br />"; echo "<br />"; // Mathematical representations are the same echo sprintf("%e", 1.5 * 0.19); echo "<br />"; echo "<br />"; echo sprintf("%e", 0.285); echo "<br />"; echo "<br />"; // This expression is TRUE, that's correct echo (0.285 == 0.285) ? "TRUE" : "FALSE"; echo "<br />"; ?> Expected result: ---------------- This expression should return TRUE, because 1.5 * 0.19 is 0.285 Actual result: -------------- Actual result is FALSE ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47449&edit=1