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

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

    function isInteger(n) {
       return ((typeof n==='number')&&(n%1===0));
    }
    
    function isFloat(n) {
       return ((typeof n==='number')&&(n%1!==0));
    }
    
    function isNumber(n) {
       return (typeof n==='number');
    }
    

提交回复
热议问题