How to check whether input value is integer or float?

user569125 picture user569125 · Jan 18, 2011 · Viewed 119.2k times · Source

How to check whether input value is integer or float?

Suppose 312/100=3.12 Here i need check whether 3.12 is a float value or integer value, i.e., without any decimal place value.

Answer

Alex picture Alex · Jan 18, 2011

You should check that fractional part of the number is 0. Use

x==Math.ceil(x)

or

x==Math.round(x)

or something like that