is_float

(PHP 3, PHP 4, PHP 5)

is_float -- 检测变量是否是浮点型

描述

bool is_float ( mixed var )

如果 varfloat 则返回 TRUE,否则返回 FALSE

注: 若想测试一个变量是否是数字或数字字符串(如表单输入,它们通常为字符串),必须使用 is_numeric()

参见 is_bool()is_int()is_integer()is_numeric()is_string()is_array()is_object()


add a note add a note User Contributed Notes
phper
26-Jan-2006 04:08
A better way to check for a certain number of decimal places is to use :

$num_dec_places = 2;
number_format($value,$num_dec_places);
kirti dot contact at gmail dot com
19-Oct-2005 02:18
To check a float only should contain certain number of decimal places, I have used this simple function below

<?
function is_deccount($number,$decimal=2){
  
$m_factor=pow(10,$decimal);
   if((int)(
$number*$m_factor)==$number*$m_factor)
       return
true;
   else
       return
false;
 }   
?>