專業鋁門窗、鍛造門設計及安裝
價格便宜、品質好、設計佳,值得您信賴
油漆30多年專業技術團隊
幫您輕鬆搞定房子抓漏防水等惱人問題

首頁  •  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 人回應

    姓名:
    佈告內容: