November 8, 2023
Number object and
Number object provides methods that can be used to inspect the characteristics of numeric values. One approach to check if a number is a float is to compare it with its integer part obtained using
parseFloat and strict comparison
parseFloat can be used to ensure the number remains the same when its floating-point representation is parsed from a string. Strict comparison to the original number then reveals its type.
Mathematical functions like
Math.ceil can also be used to check for float numbers by comparing the original number with the result of the floor or ceil operation.
A straightforward method provided by ES6 is
Number.isInteger, which directly checks if a number is an integer, hence its negation would imply a float.
How to Truncate Date in MySQL