note 79002 added to function.is-float
| From: | KenaniahCerny at osu1 dot php dot net | Date: | Tue, 06 Nov 2007 19:21:41 +0000 |
| Subject: | note 79002 added to function.is-float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132050@lists.php.net to get a copy of this message | ||
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
----
Server IP: 64.71.164.2
Probable Submitter: 96.229.185.158
----
Manual Page -- http://www.php.net/manual/en/function.is-float.php
Edit -- https://master.php.net/note/edit/79002
Del: integrated -- https://master.php.net/note/delete/79002/integrated
Del: useless -- https://master.php.net/note/delete/79002/useless
Del: bad code -- https://master.php.net/note/delete/79002/bad+code
Del: spam -- https://master.php.net/note/delete/79002/spam
Del: non-english -- https://master.php.net/note/delete/79002/non-english
Del: in docs -- https://master.php.net/note/delete/79002/in+docs
Del: other reasons-- https://master.php.net/note/delete/79002
Reject -- https://master.php.net/note/reject/79002
Search -- https://master.php.net/manage/user-notes.php