How to check whether input value is integer or float?

前端 未结 8 1096
庸人自扰
庸人自扰 2020-12-13 05:44

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

8条回答
  •  一个人的身影
    2020-12-13 06:20

    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

提交回复
热议问题