isFloat()
isFloat(
value):boolean
Checks if a value is a float (finite number that is not an integer).
remarque
This checks for numbers that have a decimal part.
Parameters
value: unknown
The value to check.
Returns: boolean
true if the value is a float, false otherwise.
Since
2.0.0
Example
isFloat(1.5); // => true
isFloat(1.0); // => false
isFloat(1); // => false
isFloat(Infinity); // => false
isFloat('1.5'); // => false
How it works?
Checks if a value is a float (finite number with decimal part).
Examples
| Value | Result | Reason |
|---|---|---|
1.5 | true | Has decimal |
1.0 | false | No decimal part |
1 | false | Integer |
Infinity | false | Not finite |
-Infinity | false | Not finite |
NaN | false | Not finite |
'1.5' | false | Not a number |
Float vs Integer
Use Cases
Detect decimal numbers 📌
Check if a number has a fractional part. Useful for differentiating integers from floating-point values in data parsing.
if (isFloat(price)) {
console.log(`Precise price: ${price}`);
}
Validate geometric coordinates
Ensure coordinates are precise floating-point numbers. Perfect for mapping applications or graphics rendering.
if (isFloat(latitude) && isFloat(longitude)) {
updateMarkerPosition(latitude, longitude);
}
true
false