首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

将人民币中金额数字转化为中文大写代码php

主体代码:

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("",$this->cnyMapUnit(str_split($int),$cnygrees)),""));

$ret = implode("",array_reverse($this->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;

}

调用代码:echo toChineseNumber($money);

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20181128A12K9900?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券