zoukankan      html  css  js  c++  java
  • 金额转换方法

        /**
         * 把金额由元转为分
         */
        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';
            }
        }
  • 相关阅读:
    Codeforces 385C
    Codeforces 496C
    HDU 6114 Chess
    Codeforces 839B
    Codeforces 483B
    Codeforces 352B
    Codeforces 768B
    Codeforces 38B
    Codeforces 735B
    Codeforces 534B
  • 原文地址:https://www.cnblogs.com/-mrl/p/6269297.html
Copyright © 2011-2022 走看看