I'm using a function to to verify whether the number passed as a parameter is a float or an integer in JavaScript.
The method is working for numbers such as '4.34' i.e. with a non-zero decimal but it fails for numbers such as '3.0', returning integer instead of float.
This is the code I have been able to come up with so far
function dataType(x) {
if (typeof x === 'number' && ){
if (Math.round(x) === x ){
return 'integer';
}
return 'float';
}
}
console.log(dataType(8)); //integer
console.log(dataType(3.01)); //float
console.log(dataType(3.0)); // should return float
I would really appreciate some help on how to do this in JavaScript.
Thanks in advance.
Update: I want console.log(dataType(3.0)); to return float.