Edit report at https://bugs.php.net/bug.php?id=64323&edit=1
ID: 64323 Updated by: ras...@php.net Reported by: guaycuru at gmail dot com Summary: Float inconsistency between echo/var_dump and tests -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Scripting Engine problem Operating System: Any PHP Version: 5.4.12 Block user comment: N Private report: N New Comment: You are getting the display precision confused with the internal representation of a float. You can change the display precision with ini_set('precision',32); If you do that your output becomes: float(0.30000000000000004440892098500626) Something is wrong here! It is just at the default display precision you end up with 0.3 in your case, but that has nothing to do with the internal representation of the float. Previous Comments: ------------------------------------------------------------------------ [2013-02-28 14:27:43] guaycuru at gmail dot com Description: ------------ So, I know that due to the way computers store float numbers, we end up with some oddities. This BUG is NOT about that. Instead, I found some inconsistencies on how PHP handle that, and it's easy to think of cases that those inconsistencies would end up causing lots of wasted hours debugging. Please see test script, it should be pretty self explanatory. My change request is that, since float / echo deal with that inconsistency (rounding 0.3000000000000000444089209850062616169452667236328125 to 0.3), so should control flow functions like IF, WHILE, etc... Tested on PHP 5.3.22 and PHP 5.4.12 Test script: --------------- <?php $a = 0.1; $b = 0.2; var_dump($a + $b); if($a + $b <= 0.3) echo "All is right in the universe!"; else echo "Something is wrong here!"; ?> Expected result: ---------------- float(0.3) All is right in the universe! Also, this result is acceptable: float(0.3000000000000000444089209850062616169452667236328125) Something is wrong here! Actual result: -------------- float(0.3) Something is wrong here! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64323&edit=1