/**
     * 把金额由元转为分
     */
    public static function amountToFen($amount){
        $amount = $amount * 100;
        if(strpos($amount, '.') !== false){
            return ceil($amount);
        }
        return $amount;
    }

    /**
     * 把金额由分转为元
     */
    public static function amountToYuan($amount, $transToNull = false)
    {
        //是否转换
        if($transToNull && (is_null($amount) || empty($amount))) return null;
        if(is_null($amount) || empty($amount)) return '0.00';
        $amount /= 100;
        $strpos = strpos($amount, '.');
        if ($strpos !== false) {
            if (strlen($amount) - $strpos != 3) {
                return $amount . '0';
            }
            return $amount;
        } else {
            return $amount . '.00';
        }
    }

 

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-09-09
  • 2021-10-05
  • 2021-09-18
  • 2022-12-23
  • 2021-06-24
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案