廣告招牌設計巧思運用,靈活搭配字型
燈光、安裝位置,幫您高調搶商機
油漆工程居住高品質的隔音門,無聲靜悄悄
引領業界,專營各式門窗,提供免費到府丈量

首頁  •  j2h 論壇 • 程式設計討論     • 

[教學]阿拉伯數字轉國字

房東:小新
發表時間:2008-07-31


$new_string = "1000000100100" ;

$chinese_text = array("零","壹","貳","參","肆","伍","陸","柒","捌","玖") ;
$chinese_unit = array("","","拾","佰","仟","","拾","佰","仟","","拾","佰","仟","","拾","佰","仟") ;

for ($i=0;$i < strlen($new_string) ; $i++){

if ($a_unit == null) {
//偵測位數
$a_unit = strlen($new_string) ;
}
//取出阿拉伯數數字
$a = substr($new_string,$i,1) ;

if($a != 0){
//阿拉伯轉中文
$out_string .= $chinese_text[$a] ;
$out_string .= $chinese_unit[$a_unit] ;
}
//單位轉換
if($a_unit == 5){

$out_string .= "萬" ;
}elseif($a_unit == 9){

$out_string .= "億" ;
}elseif($a_unit == 13){

$out_string .= "兆" ;
}
//位數遞減
$a_unit -= 1 ;
}

$out_string .= "元整
" ;
//去除億萬,兆億問題
$out_string = str_replace("億萬","億",$out_string) ;
$out_string = str_replace("兆億","兆",$out_string) ;

echo $out_string ;
?>




  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務



  •  共 0 人回應

    姓名:
    佈告內容:
    其他選項: