Skip to content

Commit

Permalink
Add hasDecimals
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed May 1, 2022
1 parent e89c56d commit f0c4961
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions snippets/hasDecimals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Number has decimal digits
tags: math
expertise: beginner
author: chalarangelo
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
```

0 comments on commit f0c4961

Please sign in to comment.