Checks if a number has any decimals digits
- Use the modulo (
%
) operator to check if the number is divisible by1
and return the result.
代码实现
const hasDecimals = num => num % 1 !== 0;
hasDecimals(1); // false
hasDecimals(1.001); // true
Checks if a number has any decimals digits
%
) operator to check if the number is divisible by 1
and return the result.
const hasDecimals = num => num % 1 !== 0;
hasDecimals(1); // false
hasDecimals(1.001); // true