Created
June 23, 2012 22:03
-
-
Save berkes/2980236 to your computer and use it in GitHub Desktop.
gotcha with PHP typecasting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$amount = 17.50; | |
print (int) $amount * 100; # => 1700 # My implementation. I was wrong. | |
print (int) ($amount * 100); # => 1750 # After bugfix. PHP first casts, then multiplies. |
Heh. Thanks. I had to "anonimize" the price a little. But forgot half of hem :)
Changed it :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you using an old Pentium CPU? I hope that PHP never returns 1750 for "(int) (12.50 * 100)".
Feel free to merge the fix from my fork :)