首页 > 代码库 > 将金额转换成大写表示
将金额转换成大写表示
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) "贰仟壹佰肆拾伍亿陆仟贰佰伍拾肆万壹仟贰佰零伍圆肆角玖分"
将金额转换成大写表示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。