Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created February 2, 2013 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/4698767 to your computer and use it in GitHub Desktop.
Save itspriddle/4698767 to your computer and use it in GitHub Desktop.
This is why you shouldn't use floating points for money in your app
~ > node -e "console.log((0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3))"
false
~ > php -r "var_dump((0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3));"
bool(false)
~ > ruby -e "p (0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3)"
false
~ > python -c "print (0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3)"
False
~ > perl -e "print ((0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3) ? 'true' : 'false')"
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment