YouTip LogoYouTip

Php Is_Float Function

## PHP is_float() Function The `is_float()` function in PHP is a built-in variable handling function used to determine whether a given variable is of the float (floating-point) data type. In PHP, a float (also known as a "double" or "real number") is a number with a decimal point or a number in exponential form. --- ### Syntax ```php bool is_float ( mixed $var ) ``` #### Parameters * **`$var`**: The variable you want to evaluate. This can be of any data type (`mixed`). #### Return Value * Returns `true` if `$var` is a float, otherwise returns `false`. --- ### Aliases PHP provides two alias functions that behave identically to `is_float()`: * **`is_double()`** * **`is_real()`** *(Note: `is_real()` has been **deprecated** as of PHP 7.4.0 and **removed** in PHP 8.0.0. It is highly recommended to use `is_float()` instead).* --- ### Code Examples #### Basic Usage The following example demonstrates how `is_float()` evaluates different types of values: ```php ``` #### Output: ```text This is a float value. bool(false) bool(false) bool(false) bool(false) bool(true) ``` --- ### Key Considerations #### 1. Numeric Strings vs. Floats `is_float()` strictly checks the **data type** of the variable, not its content. If a variable contains a numeric string (such as `"12.5"`), `is_float()` will return `false` because the type is `string`, not `float`. If you need to check whether a variable is a number or a numeric string (commonly found in HTML form inputs or API payloads), you should use **`is_numeric()`** instead. ```php $numeric_string = "12.5"; var_dump(is_float($numeric_string)); // Returns bool(false) var_dump(is_numeric($numeric_string)); // Returns bool(true) ``` #### 2. NaN and Infinity Special floating-point values like `NAN` (Not a Number) and `INF` (Infinity) are technically of the `float` type. Therefore, `is_float()` will return `true` for them. ```php var_dump(is_float(NAN)); // Returns bool(true) var_dump(is_float(INF)); // Returns bool(true) ```
← Php Is_Null FunctionPhp Intval Function β†’