获取小数位数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function getFloatLength($num)
{
$count = 0;
if (!is_string($num))
{
throw new \Exception('not string');
}
$num = (string) $num;
$temp = explode('.', $num);
if (sizeof($temp) > 1)
{
$decimal = end($temp);
$count = strlen($decimal);
}
return $count;
}