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.

More like this

  • Tip: Convert decimal number to hexadecimal

    Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.

    JavaScript, Math · Sep 21, 2022

  • Number to decimal mark

    Converts a number to a decimal mark formatted string.

    JavaScript, Math · Oct 22, 2020

  • Luhn check

    Implements the Luhn Algorithm, used to validate a variety of identification numbers.

    JavaScript, Math · Jan 30, 2022