Number has decimal digits

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

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this