醉菜鸟 2021-07-09 20:31:36

PHP数字转人民币金额大写

/**
* @param $number
* @return string
*/
function num_rmb($number = 0) {
$rmb_num = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];
$rmb_unit = ['分','角','元','拾','佰','仟','万','拾','佰','仟','亿'];

if($number < 0){
return 'please enter an amount greater than 0, thank you!';
}
$number = number_format($number, 2, '.', '')*100;

$len = strlen($number);
$rmb = "";
for ($i = 0;$i < $len; $i++){
$num = substr($number, $i, 1);
$unit = ($len - $i - 1) % count($rmb_unit);
if ($len - count($rmb_unit) > $i){
$unit = $unit + 3;
}
$rmb.=$rmb_num[$num].$rmb_unit[$unit];
}
return $rmb;
}
意见反馈