# Check If a Number has Decimal Places in JavaScript or Node.js

Sometimes you’re running into use-cases where you need to detect whether a given number has decimal places. This tutorial shows you how to do that!

## Detect If a Number Has Decimal Places

Generally, you may want to apply formatting on numbers. And you may want to round numbers having decimal places before formatting. Here’s a utility method helping you to detect whether a given number has decimal places:

``````/**
* Determine whether the given `num` has decimal places.
*
* @param {Number} num
*
* @returns {Boolean}
*/
function hasDecimalPlaces (num) {
return !Number.isSafeInteger(num)
}
``````

Please notice: JavaScript comes with precision limits on floating-point numbers. For example, you would expect a number like `3.0000000000000001` to have decimal places. But JavaScript treats this number as an integer. That’s the reason the `hasDecimalPlaces` utility returns `false`.

### Why not Use `Number.isInteger`?

The reason we don’t use `Number.isInteger` is that this method accepts integers that are out of range. That means `isInteger` would return `true` for numbers out of range, even though they are not integers.

Enjoy!

# Explore the Library

Find interesting tutorials and solutions for your problems.