List Info

Thread: note 79002 added to function.is-float




note 79002 added to function.is-float
user name
2007-11-06 13:21:41
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 -- ht
tp://www.php.net/manual/en/function.is-float.php
Edit        -- https://master
.php.net/note/edit/79002
Del: integrated  -- h
ttps://master.php.net/note/delete/79002/integrated
Del: useless     -- http
s://master.php.net/note/delete/79002/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/79002/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/79002
Reject      -- https://mast
er.php.net/note/reject/79002
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )