is_float
Checks whether a value is a float.
Syntax
is_float(mixed $value): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The value to check. |
Return value
bool`true` if the type of the value is `float`.
Examples
A float, division results and a string:
<?php
var_dump(is_float(1.5));
var_dump(is_float(10 / 4));
var_dump(is_float(10 / 2));
var_dump(is_float('1.5'));Output:
bool(true)
bool(true)
bool(false)
bool(false)Notes
Division with / yields an int when integers divide evenly and a float otherwise. A numeric string is not a float: check it with is_numeric().
See also
- is_int — Checks whether a value is an integer.
- is_numeric — Checks whether a value is a number or a numeric string.
- floatval — Converts a value to a float.
Related recipes
In the tutorial
- Data types — The main PHP data types — strings, numbers, booleans, arrays and null.