时间:2021-07-01 10:21:17 帮助过:27人阅读
<p><?php /* * 元后面才加整,有角的就不加整字。 */ function num2rmb ($num){ $c1=”零壹贰叁肆伍陆柒捌玖”; $c2=”分角元拾佰仟万拾佰仟亿”;</p> <p>$num=round($num,2); $num=$num*100; if(strlen($num)>10){ return “oh,sorry,the number is too long!”; }</p> <p>$i=0; $c=”";</p> <p>while (1){ if($i==0){ $n=substr($num,strlen($num)-1,1); }else{ $n=$num %10; }</p> <p>$p1=substr($c1,2*$n,2); $p2=substr($c2,2*$i,2); if($n!=’0′ || ($n==’0′ &&($p2==’亿’ || $p2==’万’ || $p2==’元’ ))){ $c=$p1.$p2.$c; }else{ $c=$p1.$c; }</p> <p>$i=$i+1; $num=$num/10; $num=(int)$num;</p> <p>if($num==0){ break; } } $j = 0; $slen=strlen($c); while ($j< $slen) { $m = substr($c,$j,4);</p> <p>if ($m==’零元’ || $m==’零万’ || $m==’零亿’ || $m==’零零’){ $left=substr($c,0,$j); $right=substr($c,$j+2); $c = $left.$right; $j = $j-2; $slen = $slen-2; } $j=$j+2; }</p> <p>if(substr($c,strlen($c)-2,2)==’零’){ $c=substr($c,0,strlen($c)-2); }</p> <p>if(substr($c,-2,2)==’元’){ return $c.”整”; }else{ return $c; }</p> <p>}</p> <p>$out=num2rmb(1333); echo $out; ?> </p>
以上就是货币数字转换为中文大写的php代码 的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!