Files
30-seconds-of-code/javascript/snippets/has-decimals.md
2023-05-01 22:35:56 +03:00

411 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Number has decimal digits snippet
math
chalarangelo man-cup-laptop 2022-05-13T05:00:00-04:00

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