Number has decimal digits

Angelos Chalaris · JavaScript, Math · May 13, 2022

Checks if a number has any decimals digits

  • Use the modulo (%) 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

Would you like to help us improve 30 seconds of code?Take a quick survey

Recommended snippets