Navigate back to the homepage

# How to check if number is integer or float in javascript?

Infinitbility,Â
JavaScript,Â
June 1st, 2022 Â· 1 min read

Hi Friends đź‘‹,

Welcome To Infinitbility! âť¤ď¸Ź

To check number is an integer or float, JavaScript provides `isInteger()` method just pass your number as a parameter and it will return `true` if the number is an integer or else false.

Today, Iâ€™m going to show How do I check if the number is an integer or float in Javascript, here I will use the javascript string `isInteger()` method, to check if a number is an integer or float.

### What is a `isInteger()` method?

The `Number.isInteger()` method determines whether the passed value is an integer.

Letâ€™s start the todayâ€™s tutorial How do you check if the number is integer or float in JavaScript?

In the following example, we will create our custom function to check number is int or float, where we will also add some more conditions like the given parameter should be a number and after that, we will check number is integer or float.

`.css-1chxjt6{position:absolute;right:22px;top:24px;padding:8px 12px 7px;border-radius:5px;color:#6f7177;-webkit-transition:background 0.3s ease;transition:background 0.3s ease;}.css-1chxjt6:hover{background:rgba(255,255,255,0.07);}.css-1chxjt6[data-a11y="true"]:focus::after{content:"";position:absolute;left:-2%;top:-2%;width:104%;height:104%;border:2px solid var(--theme-ui-colors-accent,#6166DC);border-radius:5px;background:rgba(255,255,255,0.01);}@media (max-width:45.9375em){.css-1chxjt6{display:none;}}1// function to check if a number is a float or integer value2function validateNumber(x) {3    // check if the passed value is a number4    if(typeof x == 'number' && !isNaN(x)){5        // check if it is integer6        if (Number.isInteger(x)) {7            console.log(`\${x} is integer.`);8        }9        else {10            console.log(`\${x} is a float value.`);11        }12    } else {13        console.log(`\${x} is not a number`);14    }15}1617validateNumber('hello');18validateNumber(44);19validateNumber(3.4);20validateNumber(-3.4);21validateNumber(NaN);`

In the above program, we have taken examples of every possible value like parameter if string, number, positive value, a negative value, or NaN values. letâ€™s check the output.

I hope itâ€™s help you, All the best đź‘Ť.

### Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

### Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Request New Tutorial or Article on mail [email protected]

### Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

### How to check if the first letter of a string is uppercase in javascript?

Example of check if the first letter of a string is uppercase in javascript with step by step guide.

May 31st, 2022 Â· 1 min read

### how to check if the first character of a string is a letter in javascript?

Example of check if the first character of a string is a letter in javascript with step by step guide.

May 31st, 2022 Â· 1 min read