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);
is_float
(PHP 4, PHP 5)
is_float — 変数が float 型かどうか調べる
説明
bool is_float ( mixed $var )与えられた変数が float 型かどうかを調べます。
注意: 変数が数値もしくは数値文字列の場合 (フォームからの入力の場合は 常に文字列となります) 、is_numeric() を使用する必要があります。
パラメータ
- var
評価する変数
返り値
もし var が float 型 の場合 TRUE、 そうでない場合は FALSE を返します。
参考
| is_bool() |
| is_int() |
| is_numeric() |
| is_string() |
| is_array() |
| is_object() |
is_float
phper
26-Jan-2006 05:08
26-Jan-2006 05:08
kirti dot contact at gmail dot com
19-Oct-2005 03:18
19-Oct-2005 03: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;
}
?>