Check a value is float or int in jquery

int, jquery

Solution

use `typeof` to check the type, then `value % 1 === 0` to identify the int as bellow,

if(typeof value === 'number'){
   if(value % 1 === 0){
      // int
   } else{
      // float
   }
} else{
   // not a number
}

Problem

I have the following html field, for which i need to check whether the input value is float or int, ``` <p class="check_int_float" name="float_int" type="text"></p> $(document).ready(function(){ $('.check_int_float').focusout(function(){ var value = this.value if (value is float or value is int) { // do something } else { alert('Value must be float or int'); } }); }); ``` So how to check whether a value is float or int in jquery. I need to find/check both cases, whether it is a float, or int, because later if the value was `float` i will use it for some purpose and similarly for `int`.

Original source

Related problems