Skip to content

Instantly share code, notes, and snippets.

@berkes
Created June 23, 2012 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save berkes/2980236 to your computer and use it in GitHub Desktop.
Save berkes/2980236 to your computer and use it in GitHub Desktop.
gotcha with PHP typecasting
<?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.
@skwashd
Copy link

skwashd commented Jun 24, 2012

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 :)

@berkes
Copy link
Author

berkes commented Jun 24, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment