note 80326 added to function.is-float
| From: | WHITEnewmediaarchitects-Jeroen at osu1 dot php dot net | Date: | Thu, 10 Jan 2008 11:24:01 +0000 |
| Subject: | note 80326 added to function.is-float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134993@lists.php.net to get a copy of this message | ||
The above printed "is_true_float" function is not correct.
It gives wrong answers on the following tests:
is_true_float("-4,123"); # returns false
is_true_float("0,123"); # returns false
So I changed the function to correctly handle qouted negative floats and quoted floats near zero:
<?php
function is_true_float($mVal)
{
return ( is_float($mVal)
|| ( (float) $mVal != round($mVal)
|| strlen($mVal) != strlen( (int) $mVal) )
&& $mVal != 0 );
}
?>
----
Server IP: 213.249.64.162
Probable Submitter: 80.126.184.94
----
Manual Page -- http://www.php.net/manual/en/function.is-float.php
Edit -- https://master.php.net/note/edit/80326
Del: integrated -- https://master.php.net/note/delete/80326/integrated
Del: useless -- https://master.php.net/note/delete/80326/useless
Del: bad code -- https://master.php.net/note/delete/80326/bad+code
Del: spam -- https://master.php.net/note/delete/80326/spam
Del: non-english -- https://master.php.net/note/delete/80326/non-english
Del: in docs -- https://master.php.net/note/delete/80326/in+docs
Del: other reasons-- https://master.php.net/note/delete/80326
Reject -- https://master.php.net/note/reject/80326
Search -- https://master.php.net/manage/user-notes.php