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

前端 未结 30 2604
栀梦
栀梦 2020-11-22 00:01

How to find that a number is float or integer?

1.25 --> float  
1 --> integer  
0 --> integer  
0.25 --> float
<         


        
30条回答
  •  一整个雨季
    2020-11-22 00:36

    Here's what I use for integers:

    Math.ceil(parseFloat(val)) === val
    

    Short, nice :) Works all the time. This is what David Flanagan suggests if I'm not mistaken.

提交回复
热议问题