# How do I check that a number is float or integer - JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

#### JavaScript for beginners

Best Seller

74 Lectures 10 hours

#### Modern Javascript for Beginners + Javascript Projects

Most Popular

112 Lectures 15 hours

#### The Complete Full-Stack JavaScript Course!

Best Seller

96 Lectures 24 hours

Let’s say we have the following variables −

var value1 = 10;
var value2 = 10.15;

Use the Number() condition to check that a number is float or integer −

Number(value) === value && value % 1 !== 0;
}

## Example

Following is the code −

function checkNumberIfFloat(value) {
return Number(value) === value && value % 1 !== 0;
}
var value1 = 10;
var value2 = 10.15;
if (checkNumberIfFloat(value1) == true)
console.log("The value is float=" + value1);
else
console.log("The value is not float=" + value1);
if (checkNumberIfFloat(value2) == true)
console.log("The value is float=" + value2);
else
console.log("The value is not float=" + value2);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo218.js.

## Output

The output is as follows −

PS C:\Users\Amit\JavaScript-code> node demo218.js
The value is not float=10
The value is float=10.15