Skip to content

Instantly share code, notes, and snippets.

@creativeaura
Created March 9, 2012 09:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creativeaura/2005729 to your computer and use it in GitHub Desktop.
Save creativeaura/2005729 to your computer and use it in GitHub Desktop.
JavaScript isFloat and isInteger
function isFloat(n){
return n === +n && n !== (n|0);
}
function isInteger(n){
return n === +n && n === (n|0);
}
@you-think-you-are-special

image

@cismous
Copy link

cismous commented Oct 31, 2018

@you-think-you-are-special

0 === 0.0 is true

@cybaj
Copy link

cybaj commented Sep 4, 2019

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