JAVA數字大寫金額轉換

2021-06-12 18:08:05 字數 1547 閱讀 3257

public

class

moneyutil ;

private

static

final

string iunit  =;

private

static

final

string dunit  =;

public

static

string tochinese(string str)  

else

if(str.indexof(".

") == 0

)   else

//integerstr去掉首0,不必去掉decimalstr的尾0(超出部分捨去)

if(!integerstr.equals(

"")) 

} //

overflow超出處理能力,直接返回

if(integerstr.length() 

>

iunit.length) 

intintegers 

=toarray(integerstr);

//整數部分數字

boolean

ismust5 

=ismust5(integerstr);

//設定萬單位

intdecimals 

=toarray(decimalstr);

//小數部分數字

return

getchineseinteger(integers, ismust5) 

+getchinesedecimal(decimals);}

private

static

inttoarray(string number) 

return

array;}

private

static

string getchineseinteger(

int integers, 

boolean

ismust5) 

== 0

?key

: (numbers[integers[i]] 

+iunit[length 

-i - 1

]));

} return

chineseinteger.tostring();}

private

static

string getchinesedecimal(

int decimals) 

return

chinesedecimal.tostring();}

private

static

boolean

ismust5(string integerstr)  

else

return

integer.parseint(subinteger) 

> 0;

}  else

} public

static

void

main(string args) }

java 數字金額大寫轉換

數字金額大寫轉換,思想先寫個完整的然後將如零拾替換成零 要用到正規表示式 public static string digituppercase double n string digit string unit string head n 0 負 n math.abs n string s for...

金額數字大寫轉換

by linsl 2008 07 23 轉化格式 function numtoch num var num ch new array 零 壹 貳 叄 肆 伍 陸 柒 捌 玖 var z unit new array 元 拾 佰 仟 萬 拾 佰 仟 億 拾 佰 仟 var point new arra...

數字轉換為大寫金額

changetochinese num num num.replace g,替換tomoney 中的 num num.replace g,替換tomoney 中的空格 num num.replace g,替換掉可能出現的 字元 if isnan num 字元處理完畢後開始轉換,採用前後兩部分分別轉換...