How to use the Number.isInteger() Method In Javascript

The Number.isInteger() Method checks if the given number is an integer or not. It returns true if the number is an integer, and false if it’s a float or not a number at all.

Syntax

Number.isInteger(number);

Example: This example uses the Number.isInteger() Method to check the Number.

Javascript




const inputNumber = 42;
const isInteger =
    Number.isInteger(inputNumber);
console.log(
    `Is ${inputNumber} an integer? ${isInteger}`
);


Output

Is 42 an integer? true

JavaScript Program to Check if a Number is Float or Integer

In this article, we will see how to check whether a number is a float or an integer in JavaScript. A float is a number with a decimal point, while an integer is a whole number or a natural number without having a decimal point.

Table of Content

  • Using the Number.isInteger() Method
  • Using the Modulus Operator (%)
  • Using Regular Expressions

We will explore every approach to Check if a Number is a Float or Integer, along with understanding their basic implementations.

Similar Reads

Using the Number.isInteger() Method

...

Using the Modulus Operator (%)

The Number.isInteger() Method checks if the given number is an integer or not. It returns true if the number is an integer, and false if it’s a float or not a number at all....

Using Regular Expressions

...

Contact Us