by @kodeazy
How to check a numbr is integer or float in javascript?
- In this blog we will be discussing about how to check a number is
integer
orfloat
in javascript - for example
1
is aninteger
but1.5
isfloat
. - To check the given number is integer or float divide the number by
1
and check thereminder
- If reminder is
0
then it isinteger
else it isfloat
. -
Below is the example to find out th numbr is integr or float.
var num=1.5; if(num%1==0) console.log("Number is an Integer"); else console.log("Number is an Float");
Output:
Number is an Float