1.将人民币中金额数字转化为中文大写

echo toChineseNumber(1234567890);//壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾圆
function toChineseNumber($money){
    $money = round($money,2);
    $cnynums = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); 
    $cnyunits = array("圆","角","分");
    $cnygrees = array("拾","佰","仟","万","拾","佰","仟","亿"); 
    list($int,$dec) = explode(".",$money,2);
    $dec = array_filter(array($dec[1],$dec[0])); 
    $ret = array_merge($dec,array(implode("",cnyMapUnit(str_split($int),$cnygrees)),"")); 
    $ret = implode("",array_reverse(cnyMapUnit($ret,$cnyunits))); 
    return str_replace(array_keys($cnynums),$cnynums,$ret); 
}
function cnyMapUnit($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; 
 }

mmy123456
376 声望17 粉丝

有项目请联系:15201970281(毛毛)


« 上一篇
svn 学习记录
下一篇 »
java相关学习