How to find that a number is float
or integer
?
1.25 --> float
1 --> integer
0 --> integer
0.25 --> float
<
Here's my code. It checks to make sure it's not an empty string (which will otherwise pass) and then converts it to numeric format. Now, depending on whether you want '1.1' to be equal to 1.1, this may or may not be what you're looking for.
var isFloat = function(n) {
n = n.length > 0 ? Number(n) : false;
return (n === parseFloat(n));
};
var isInteger = function(n) {
n = n.length > 0 ? Number(n) : false;
return (n === parseInt(n));
};
var isNumeric = function(n){
if(isInteger(n) || isFloat(n)){
return true;
}
return false;
};