How to validate value is Float in Php?
In this post, This function checks whether a variable is of type float or not.
1. Code:
<?php function checkTheValueIsFloat($var){ return false !== filter_var($var, FILTER_VALIDATE_FLOAT); } var_dump(checkTheValueIsFloat("a")); echo "<br>"; var_dump(checkTheValueIsFloat("1.3")); ?>
2. Example:
Input:
Input: a Input: 1.4 Input: 1
Output:
Output: false Output: true Output: true