-1

How to find that a number is float or integer?

1.25 --> float  
1.00 --> float
1 --> integer  
0.25 --> float
Nirdesh Kumawat
  • 386
  • 2
  • 16
  • 56
  • @Arian In my question for value of `1.00` it should be return float. In provide your link it will return `integer`. – Nirdesh Kumawat Nov 13 '19 at 08:53
  • 1
    `1.00` is an integer as the decimal values are extraneous. If the issue is that you need to detect that the value **may** be a float at some point in the future based on its current value, then you cannot reliably do that in JS due to it's data typing model. – Rory McCrossan Nov 13 '19 at 09:21

1 Answers1

0

As answered here , you may try it like this.

var value = 1;
if(typeof value === 'number'){
   if(value % 1 === 0){
      // int
      console.log('integer');
   } else{
      // float
      console.log('float');
   }
} else{
   // not a number
   console.log('not a number');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
little_coder
  • 564
  • 3
  • 13