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

前端 未结 30 2564
栀梦
栀梦 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:35

    For integers I use this

    function integer_or_null(value) {
        if ((undefined === value) || (null === value)) {
            return null;
        }
        if(value % 1 != 0) {
            return null;
        }
        return value;
    }
    

提交回复
热议问题