W3docs

is_float()

The is_float() function is a built-in function in PHP that checks whether a variable is a float or not. A float is a data type that represents a decimal number.

Introduction

is_float() is a built-in PHP function that checks whether a variable holds a floating-point value (a number with a decimal part, like 3.14). It returns a boolean, so it's the standard way to confirm a value is a float before you run float-only logic on it.

A key thing to understand up front: is_float() tests the variable's type, not its mathematical value. The integer 5 and the float 5.0 are equal in value, but only 5.0 is a float. "3.14" (a string of digits) is not a float either — even though it looks like one.

This page covers the syntax, the common cases and surprises, how is_float() differs from related functions, and when you'd actually reach for it.

Syntax

is_float(mixed $value): bool
PartMeaning
$valueThe variable to test. Any type is accepted.
Return valuetrue if $value is of type float, otherwise false.

is_double() is an alias of is_float() — they behave identically, so use whichever name reads better to you.

Basic example

php— editable, runs on the server

When you echo a boolean, PHP prints 1 for true and an empty string for false — which is why the second line looks blank. To see a clear label, use var_dump() instead:

<?php
var_dump(is_float(3.14));   // bool(true)
var_dump(is_float(42));     // bool(false)
?>

What counts as a float (and what doesn't)

The biggest gotcha is that a numeric string is not a float. is_float() only returns true for values that are actually stored with the float type.

<?php
var_dump(is_float(3.14));      // bool(true)  — float literal
var_dump(is_float(1.5e3));     // bool(true)  — scientific notation = 1500.0
var_dump(is_float(0.0));       // bool(true)  — zero is still a float
var_dump(is_float(10));        // bool(false) — integer, not float
var_dump(is_float("3.14"));    // bool(false) — string, even though it looks like one
var_dump(is_float(3.14 + 1));  // bool(true)  — float arithmetic yields a float
var_dump(is_float(10 / 3));    // bool(true)  — division produces a float
?>

Note that 10 / 3 is a float even though both operands are integers: PHP division returns a float whenever the result isn't a whole number.

Handling numeric strings

If your value might be a numeric string (for example, from $_GET, $_POST, or a CSV file), is_float() will report false. Use is_numeric() to detect numeric strings, or cast first:

<?php
$input = "9.99";  // e.g. a price submitted from a form

var_dump(is_float($input));            // bool(false) — it's a string
var_dump(is_numeric($input));          // bool(true)  — looks like a number
var_dump(is_float((float) $input));    // bool(true)  — cast it first
?>

For full coverage of detecting numeric input, see is_numeric() and PHP Data Types.

A practical guard

A common use is validating a value before doing math that only makes sense on a float:

<?php
function applyDiscount(mixed $price, float $rate): float
{
    if (!is_float($price)) {
        // normalize numeric strings/ints into a float
        $price = (float) $price;
    }
    return $price - ($price * $rate);
}

echo applyDiscount(49.99, 0.10) . "\n";  // 44.991
echo applyDiscount("20", 0.25) . "\n";   // 15
?>
FunctionReturns true when the value is…
is_float() / is_double()a float (3.14, 1.5e3)
is_int()an integer (42)
is_string()a string ("3.14")
is_numeric()a number or a numeric string
is_bool()a boolean (true/false)

If you just need "is this any kind of number, including a string version," reach for is_numeric(). If you specifically need the float type, use is_float().

Conclusion

is_float() (and its alias is_double()) checks whether a variable's type is float, returning a boolean. Remember that it tests type, not value: integers and numeric strings both return false, even when they represent decimal-looking numbers. When you're working with user input — which arrives as strings — pair it with is_numeric() or cast with (float) before treating a value as a float.

Practice

Practice
What is the function of 'is_float' function in PHP?
What is the function of 'is_float' function in PHP?
Was this page helpful?