计算机中人民币数字格式,数字转人民币金额大写
numToRmb.php
header("content-type:text/html;charset=utf-8");
function numToRmb($num){
$rmbNum = ['零','壹','貳','叁','肆','伍','陸','柒','捌','玖'];
$rmbUnit = ['分','角','元','拾','佰','仟','萬','拾','佰','仟','億','拾','佰','仟','萬','拾','佰','仟'];
//數字預處理
if($num == '' || $num == 0){
return '請輸入一個大于0的金額,謝謝!';
}else {
$num = number_format($num, 2, '.', '')*100;
}
if (strlen(number_format($num, 0, '', ''))>18) {
return '輸入的金額不得超過千萬億!';
}
//開始數字轉換人民幣大寫
$out1 = 0;
$numRmb = '';
$unit = '';
$rmb = '';
for ($out1 = 0 ; $out1 < strlen(number_format($num, 0, '', '')) ; $out1++) {
$numRmb = $rmbNum[substr(number_format($num, 0, '', ''), $out1, 1)];
$unit = $rmbUnit[strlen(number_format($num, 0, '', ''))-$out1-1];
$rmb = $rmb.$numRmb.$unit;
}
// 將大寫人民幣中的零進行調整
$rmbStrlen = strlen($rmb);
for ($out2=0; $out2 < $rmbStrlen; $out2=$out2+3) {
$tempRmb = substr($rmb, $out2, 6);
if ($tempRmb=='零元'||$tempRmb=='零萬'||$tempRmb=='零億') {
$left = substr($rmb, 0, $out2);
$right = substr($rmb, $out2+3);
$rmb = $left.$right;
$out2 = $out2 - 3;
$rmbStrlen = $rmbStrlen - 3;
}elseif ($tempRmb=='零拾'||$tempRmb=='零佰'||$tempRmb=='零仟') {
$left = substr($rmb, 0, $out2+3);
$right = substr($rmb, $out2+6);
$rmb = $left.$right;
$out2 = $out2 - 3;
$rmbStrlen = $rmbStrlen - 3;
}elseif ($tempRmb=='零分'||$tempRmb=='零角') {
$left = substr($rmb, 0, $out2);
$right = substr($rmb, $out2+6);
$rmb = $left.$right;
$out2 = $out2 - 6;
$rmbStrlen = $rmbStrlen - 6;
}
if ($tempRmb=='零零') {
$left = substr($rmb, 0, $out2);
$right = substr($rmb, $out2+3);
$rmb = $left.$right;
$out2 = $out2 - 3;
$rmbStrlen = $rmbStrlen - 3;
}
if(substr($rmb,strlen($rmb)-3)=='元') {
$rmb = $rmb.'整';
}
}
return $rmb;
}
echo numToRmb($_POST['num']);
?>
總結
以上是生活随笔為你收集整理的计算机中人民币数字格式,数字转人民币金额大写的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4G物联网卡配置
- 下一篇: ZEGO RTC Meetup 实时音视