Created
March 9, 2012 09:01
-
-
Save creativeaura/2005729 to your computer and use it in GitHub Desktop.
JavaScript isFloat and isInteger
This file contains 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
function isFloat(n){ | |
return n === +n && n !== (n|0); | |
} | |
function isInteger(n){ | |
return n === +n && n === (n|0); | |
} |
3 === +3
true
3 === (3|0)
true
3.0 === (3.0|0)
true
3.0 === +3.0
true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@you-think-you-are-special
0 === 0.0
is true