zoukankan      html  css  js  c++  java
  • 人民币大写转化

        public function test_cny(){
            echo $this->cny(44.55);
        }
    
        /***
         *人民币大写转化;~~~未测试;~~~~
         */
        public 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);
        }
    
    
        public 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;
        }
    

      

  • 相关阅读:
    js forEach方法
    day1总结
    jupyter notebook
    java_13网络编程
    原生 input radio 优化
    JQ 获取 input file 图片 显示在对应位置
    math.js 使用
    前端优化
    文字动态颜色变化效果
    谷歌,火狐隐藏滚动条
  • 原文地址:https://www.cnblogs.com/pansidong/p/8443743.html
Copyright © 2011-2022 走看看