码迷,mamicode.com
首页 > 其他好文 > 详细

人民币数字转化为大写的汉文

时间:2020-07-09 19:44:01      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:UNC   lis   ***   each   rev   cti   foreach   private   this   

    public function ggg(){
        $s = $this->cny(‘122‘);
        echo $s;      //壹佰贰拾贰元
    }




    /***
     *人民币大写转化;~~~
     */
    private function cny($ns) {
        static $cnums = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"),
        $cnyunits = array("元","角","分"),                         //----表格背景有元;
        $grees = array("拾","佰","仟","万","式","拜","仟");//"拾","佰","仟","万","式"(拾),"拜"(佰),"签"(仟),"亿"~~临时替代~~临时替代

        list($ns1,$ns2) = explode(".",$ns,2);
        $ns2 = array_filter(array($ns2[1],$ns2[0]));
        $ret = array_merge($ns2,array(implode("",$this->_cny_map_unit(str_split($ns1),$grees)),""));
        $ret = implode("",array_reverse($this->_cny_map_unit($ret,$cnyunits)));
        return str_replace(array_keys($cnums),$cnums,$ret);
    }


    private function _cny_map_unit($list,$units) {
        $ul = count($units);
        $xs = array();
        foreach (array_reverse($list) as $x) {
            $l = count($xs);
            if ($x!="0" || !($l%4)) $n=($x==‘0‘?‘‘:$x).($units[($l-1)%$ul]);
            else $n = is_numeric($xs[0][0])?$x:‘‘;
            array_unshift($xs,$n);
        }
        return $xs;
    }

人民币数字转化为大写的汉文

标签:UNC   lis   ***   each   rev   cti   foreach   private   this   

原文地址:https://www.cnblogs.com/pansidong/p/13275317.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!