將金額轉換成大寫漢字

2021-04-13 02:17:40 字數 2717 閱讀 4994

integer li_i

integer  li_lendec,li_lenint

integer li_amout_flag

integer li_point

string ls_amount_string

string  ls_single

string  ls_single_dx

string   ls_single_wei

string ls_mw

string  ls_single_dx_bak

string  ls_dxint[13] = &

string  ls_dxdec[2] =

string  ls_sz[13] = &

string ls_amount_uppder

//如果金額為0

if ad_amout = 0.00 then

ls_amount_uppder = '零元整'

return ls_amount_uppder

else

//如果金額為負數

if ad_amout < 0.00 then

ad_amout = abs(ad_amout)

li_amout_flag = 1 //標記

end if

end if

//將金額轉換為字元型

ls_amount_string = string(ad_amout,'#0.00')

//小數點位置

li_point = pos(ls_amount_string,'.')

//獲得金額整數字長度

li_lenint = len(mid(ls_amount_string, 1, li_point - 1))

if li_lenint > 13 then

messagebox('提示資訊','整數部分不能超過13位!', stopsign!)

ls_amount_uppder = 'error'

return ls_amount_uppder

end if

//小數部分

if right(ls_amount_string,2) = '00' then

li_lendec = 0

else

li_lendec = 2

end if

ls_amount_uppder = ' '

//整數字轉換

for li_i = 1 to li_lenint

//按高位依次取單個數字

ls_single = mid(mid(ls_amount_string, 1, li_lenint), li_i,1)

//單個轉為人民幣大寫

ls_single_dx = ls_sz[integer(ls_single) + 1]

//位ls_single_wei = ls_dxint[li_lenint - li_i +1]

//記錄ls_amount_uppder末位

if ls_amount_uppder <> ' ' then

ls_mw = mid(ls_amount_uppder, len(ls_amount_uppder) - 1 ,2)

else

ls_mw = ' '

end if

//避免重複寫「零」

if ls_single_dx = '零' and &

(ls_mw = '零' or ls_single_dx = ls_single_dx_bak or &

ls_single_wei = '元' or ls_single_wei = '萬' or &

ls_single_wei = '億') then

ls_single_dx = ''

end if

if ls_single = '0' and ls_single_wei<>'元' and ls_single_wei <>'萬' &

and ls_single_wei <>'億' then

ls_single_wei = ''

end if

if (ls_single_wei = '元' or ls_single_wei = '萬' or ls_single_wei = '億') &

and ls_mw = '零' and ls_single = '0' then

ls_amount_uppder = mid(ls_amount_uppder,1,len(ls_amount_uppder) - 2)

ls_mw = mid(ls_amount_uppder,len(ls_amount_uppder) - 1,2)

if (ls_single_wei = '元' and ls_mw = '萬' or &

ls_single_wei = '萬'and ls_mw = '億') then

ls_single_wei = ''

end if

end if

ls_amount_uppder = ls_amount_uppder + ls_single_dx + ls_single_wei

//記錄

ls_single_dx_bak = ls_single_dx

next

//小數字轉換

for li_i = 1 to li_lendec

ls_single = mid (mid(ls_amount_string, li_lenint+2, li_lendec),li_i,1)&

將金額轉換成大寫表示

function cny ns else 處理漢字中的語義問題 ns1 str replace 零零零零萬 零零零 零零 零 零 零 implode array reverse list ns1 str replace 零億 零萬 零圓 億 萬 圓 ns1 else 處理小數部分 if empty ...

Java將小寫金額轉換成大寫

工作中遇到金額小寫轉大寫的需求。由於現成的工具包沒有找到此功能。最後搜到 如下 public class test public static string change double v long l math.round v 100 if l 0 string strvalue l i用來控制數...

小寫金額轉換成大寫

原作在sql 2000中有一些問題。修正錯誤並在sql 2000中執行通過。set nocount on select v lowerstr ltrim rtrim str n lowermoney,20,2 四捨五入為指定的精度並刪除資料左右空格 select i i 1 select v upp...