常用php

获取小数位数

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;
}

此处评论已关闭