javascript - Validate if a value is a whole number -
this question has answer here:
- how check number float or integer? 36 answers
i don't think isnan gonna work situation. want make sure variable contains whole numbers when validate it. -1.45 in case should not allowed. values such 1, 23, 334 should allowed/valid.
you can this, instead of using isnan:
var number = 1.45; if (number % 1 == 0) { alert('whole numbers!'); } else { alert('not whole numbers!'); }
Comments
Post a Comment