javascript - Validate if a value is a whole number -


this question has answer here:

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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -