将金额转换成大写表示
Posted 朱德平的技术博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将金额转换成大写表示相关的知识,希望对你有一定的参考价值。
function cny($ns) { static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"), $grees=array("圆","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"); //将数字转换成整数部分和小数部分 @list($ns1,$ns2)=explode(".",$ns,2); $list = array_reverse(str_split($ns1)); foreach ($list as $key => $value) { if($value != 0 || $key%4 == 0){ $list[$key] = $cnums[$value].$grees[$key]; }else{ $list[$key] = "零"; } } //处理汉字中的语义问题 $ns1 = str_replace(["零零零零万","零零零","零零"],["零","零","零"],implode(array_reverse($list))); $ns1 = str_replace(["零亿","零万","零圆"], ["亿","万","圆"], $ns1); //处理小数部分 if(empty($ns2)) return $ns1."整"; if($ns2[0]) $ns1 .= $cnums[$ns2[0]]."角"; else $ns1 .= "零"; if(isset($ns2[1])) $ns1 .= $cnums[$ns2[1]]."分"; else $ns1 .= "整"; return $ns1; }
$num = 214562541205.49;
dump(cny($num));
//dump
string(81) "贰仟壹佰肆拾伍亿陆仟贰佰伍拾肆万壹仟贰佰零伍圆肆角玖分"
以上是关于将金额转换成大写表示的主要内容,如果未能解决你的问题,请参考以下文章