javascript - How do I check that a number is float or integer? -
how find number float
or integer
?
1.25 --> float 1 --> integer 0 --> integer 0.25 --> float
check remainder when dividing 1:
function isint(n) { return n % 1 === 0; }
if don't know argument number need 2 tests:
function isint(n){ return number(n) === n && n % 1 === 0; } function isfloat(n){ return number(n) === n && n % 1 !== 0; }
Comments
Post a Comment