The is_float() Function: Checking for Float Data Types


**The is_float() Function: Checking for Float Data Types**

The **is_float()** function in PHP is used to determine whether a given variable is of the float data type. It takes a single argument, which is the variable to be checked.

**Syntax:**

“`php
is_float(mixed $var): bool
“`

**Parameters:**

* **$var**: The variable to be checked.

**Return Value:**

The is_float() function returns **TRUE** if the specified variable is of the float data type, and **FALSE** otherwise.

**Example:**

“`php
$num1 = 10.5;
$num2 = “10.5”;

if (is_float($num1)) {
echo “$num1 is a float.\n”;
}

if (!is_float($num2)) {
echo “$num2 is not a float.\n”;
}
“`

**Output:**

“`
10.5 is a float.
10.5 is not a float.
“`

**Use Cases:**

The is_float() function is useful in various scenarios, such as:

* **Data validation:** Ensuring that user input or data from a database is of the expected data type.
* **Type checking:** Performing operations or calculations only on variables that are known to be of the float data type.
* **Error handling:** Identifying and handling situations where a variable is not of the expected float data type.

**Note:**

* The is_float() function also returns **TRUE** for values that are of the double data type.
* To check for both float and double data types, you can use the **is_numeric()** function instead.