Skip to main content

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​

ValueResultReason
1.5 trueHas decimal
1.0 falseNo decimal part
1 falseInteger
Infinity falseNot finite
-Infinity falseNot finite
NaN falseNot finite
'1.5' falseNot 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);
}