YourJS provides the following two functions which work for all numbers including returning false
for -Infinity
and Infinity
:
function isFloat(x) {
return typeOf(x, 'Number') && !!(x % 1);
}
function isInt(x) {
return typeOf(x, 'Number') && x % 1 == 0;
}
Due to the fact that typeOf()
is a YourJS internal function, if you wanted to use these definitions you can download the version for just these functions here: http://yourjs.com/snippets/build/34