Home > Backend Development > PHP Tutorial > Convert currency numbers to Chinese uppercase php code

Convert currency numbers to Chinese uppercase php code

PHP中文网
Release: 2016-07-25 09:07:04
Original
1127 people have browsed it

The PHP code for converting currency numbers into Chinese capitals:

<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>
Copy after login

The above is the content of the PHP code for converting currency numbers into Chinese capitals. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template