C 方式實現人民幣小寫轉大寫

2021-10-04 08:25:48 字數 2609 閱讀 8796

qstring invoice::

amountsconverted

(double amount)

;// 拆分整數與小數部分

qstring stramount, strinteger, strdecimal;

// 金額字串, 整數部分, 小數部分

stramount.

setnum

(amount,

'f',2)

; strinteger = stramount.

split

('.').

at(0)

; strdecimal = stramount.

split

('.').

at(1)

; qstringlist strlinteger, strldecimal;

strlinteger = strinteger.

split(""

);strlinteger.

removefirst()

; strlinteger.

removelast()

;//移除首尾空值

strldecimal = strdecimal.

split(""

);strldecimal.

removefirst()

; strldecimal.

removelast()

;//移除首尾空值

// 構建漢字列表

qstringlist strlcninteger, strl***ecimal;

foreach (qstring str, strlinteger)

foreach (qstring str, strldecimal)

// 整數部分新增單位

int ncount = strlinteger.

size()

-1;// 總共多少位

bool yflag =

false

, sflag =

false

, bflag =

false

, qflag =

false

, wflag =

false

;int nstep =0;

for(

int i = ncount; i >=

0; i--

)else

if(strlinteger.

at(i)

!="0"

) strlcninteger.

insert

(i +1,

"拾")

, sflag =

true

;break

;case2:

// 百

if(strlinteger.

at(i)

=="0"

)else

if(strlinteger.

at(i)

!="0"

) strlcninteger.

insert

(i +1,

"佰")

, bflag =

true

;break

;case3:

// 仟

if(strlinteger.

at(i)

=="0"

)else

if(strlinteger.

at(i)

!="0"

) strlcninteger.

insert

(i +1,

"仟")

, qflag =

true

;break

;case4:

// 萬if(

!wflag)

else

strlcninteger.

insert

(i +1,

"萬")

, yflag =

true

, wflag =

true;}

else

// 億

else

strlcninteger.

insert

(i +1,

"億")

, yflag =

true;}

nstep =

1; sflag = bflag = qflag =

false

;break;}

}// 小數部分新增單位

// 分

if(strldecimal.at(

1)=="0"

)else

// 角

if(strldecimal.at(

0)=="0"

)else

qstring result = strlcninteger.

join(""

)+"圓"+ strl***ecimal.

join(""

)+"整";

return result;

}

人民幣小寫轉大寫

package day00 public class moneyelse result result.replaceall 零角 零 result result.replaceall 零分 零 result result.replaceall 角零 角 if result.equals 零零 ret...

人民幣小寫轉大寫

c code 例如 new money 200 tostring 貳佰元 namespace skyiv.util catch system.console.writeline 大寫 newmoney m 該類過載的 tostring 方法返回的是大寫金額字串 class money 建構函式 pu...

人民幣小寫轉大寫

小寫金額轉成大寫。param input return public static string numtochinese string input catch exception e int len 0 if temp.indexof 1 len temp.length else len temp...