-1

I'm a newbie at JavaScript.

In python, I can create a conditional that checks if a number is a float like this:

num = 1.5

if type(num) == float:
    print('is a float')

How can i do it in JavaScript? It is possible?

1 Answers1

1
    you can try:
    
    let x=1.5;
if(!Number.isInteger(x)) {
  console.log(`The number ${x} is a float`)
};
    
    or
    
function checkFloat(x) {
  //Check if the value is a number
   if(typeof x == 'number' &&  !isNaN(x)) {
      //Check if is integer
     if(Number.isInteger(x)) {
     //print the integer
        console.log(`${x} is integer`);
      }else {
        //print the float number
        console.log(`${x} is a float`);
      };
   }else {
     //print the value that is not a number
      console.log(`${x} is not a number`);
    };
};
Adrian
  • 26
  • 3