isFloat()
isFloat(
value):boolean
Checks if a value is a float (finite number that is not an integer).
note
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