Files
30-seconds-of-code/snippets/hasDecimals.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

392 B

title, tags, author, cover, firstSeen
title tags author cover firstSeen
Number has decimal digits 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