js check if whole number code example
Example 1: javascript how to say if a number is a whole number?
Using modulus will work:
num % 1 != 0
// 23 % 1 = 0
// 23.5 % 1 = 0.5
Example 2: check to see if number is a decimal javascript
The Number. isInteger() method determines whether a
value an integer.
This method returns true if the value is of the type
Number, and an integer (a number without decimals).
Otherwise it returns false.