Files
30-seconds-of-code/snippets/has-decimals.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

21 lines
392 B
Markdown

---
title: Number has decimal digits
tags: math
author: chalarangelo
cover: man-cup-laptop
firstSeen: 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.
```js
const hasDecimals = num => num % 1 !== 0;
```
```js
hasDecimals(1); // false
hasDecimals(1.001); // true
```