Edit report at https://bugs.php.net/bug.php?id=55843&edit=1
ID: 55843 Updated by: [email protected] Reported by: lcdtm at yahoo dot com Summary: float gives strange result when division is done prior. -Status: Open +Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: linux mandriva 2011 PHP Version: Irrelevant 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-10-04 14:29:53] lcdtm at yahoo dot com Description: ------------ float gives strange result when division is done prior. Test script: --------------- $tempout = 5037; $tempin = 5000; $tempdiff = $tempout - $tempin; $tempout = ($tempout / 100); $tempin = ($tempin / 100); $tempdiff = ($tempdiff / 100); $tempdiffActual = $tempout - $tempin; var_dump($tempdiffActual); echo "gives: float(0.37) <br>"; var_dump($tempdiff); echo "gives: float(0.37) <br>"; $something = $tempdiffActual - $tempdiff; var_dump($something); echo "gives: float(-2.5535129566379E-15). Should be 0 <br>"; Expected result: ---------------- var_dump($something); should be float(0) Actual result: -------------- var_dump($something); result: float(-2.5535129566379E-15) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55843&edit=1
