貨幣數字轉換為中文大寫的php代碼

來源:互聯網
上載者:User
貨幣數字轉換為中文大寫的php代碼 :

<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代碼 的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.