Skip to content

Instantly share code, notes, and snippets.

@berkes
Created June 23, 2012 22:03
Show Gist options
  • Select an option

  • Save berkes/2980236 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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
Copy Markdown
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