note 79002 deleted from function.is-float by nikic
| From: | nikic@php.net | Date: | Thu, 23 Aug 2012 12:04:41 +0000 |
| Subject: | note 79002 deleted from function.is-float by nikic | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190188@lists.php.net to get a copy of this message | ||
Note Submitter: Kenaniah Cerny
----
For those of you who have discovered that is_float() does not behave exactly the way you would
expect it to when passing a string, here is a function that extends is_float properly report
floating numbers given any sort of mixed variable.
<?php
function is_true_float($val){
if( is_float($val) || ( (float) $val > (int) $val || strlen($val) != strlen( (int) $val) )
&& (int) $val != 0 ) return true;
else return false;
}
?>
<?php
//Tests
'4.0' returns true
'2.1' returns true
0 returns false
"0" returns false
3. returns true
13 returns false
"12" returns false
3.53 returns true
?>
Enjoy