Menu

#1 isFloat function..

open
nobody
None
5
2007-01-02
2007-01-02
No

Try to test your isFloat() function with 0 (zero) and 1 (one).

It doesn't work!

// Fixed by Marco Rodrigues <http://Marco.Tondela.org>
function isFloat($sString)
{
$sString = preg_replace('/\s/', '', $sString);
$sString = str_replace(',', '.', $sString);

if (preg_match('/^((\-)?(\d)+((\.)?(\d)+)?)$/', $sString))
return floatval($sString);
else
return false;
}

Try this one and some function like:

0, 1, 1.00, 0.01, etc..

if (isFloat("0"))
echo "yes";
else
echo "no";

Discussion


Log in to post a comment.

MongoDB Logo MongoDB