PHP is_float() Function

Quick summary: The PHP is_float() function checks whether a variable is of type float.

PHP is_float() Syntax

is_float(mixed $value): bool
PHP

PHP is_float() Basic examples

var_dump(is_float(1.5));
PHP
Output:
bool(true)

Returns true for float values.

var_dump(is_float(1));
PHP
Output:
bool(false)

Integers are not floats.

PHP is_float() Real-world usage

$price = 9.99;
if (is_float($price)) {
    echo 'Float price';
}
PHP
Output:
Float price

Validates floating-point values.

PHP is_float() Edge cases

var_dump(is_float(NAN));
PHP
Output:
bool(true)

NAN is considered a float.

PHP is_float() Common mistakes

Expecting numeric strings to be floats

is_float checks strict type.

Incorrect
is_float("1.5");
Correct
is_numeric("1.5");

Use is_numeric to validate numeric strings.

PHP is_float() Frequently Asked Questions

What does is_float() do?

Checks if a variable is float.

Alias?

is_double().

Use case?

Decimal validation.

Handles numeric strings?

No.

Common mistake?

Using with strings.

Return type?

bool.

Strict?

Yes.

Alternative?

is_numeric().

Performance?

Fast.

Safe?

Yes.

Handles ints?

No.

Best practice?

Validate numeric input.

PHP is_float() Related PHP Functions