VB實現數字到中文金額的轉換函式

2021-04-24 16:20:05 字數 2542 閱讀 5576

private function nmoneytosmoney(nmoney as variant) as string

if isnumeric(nmoney) = false then

nmoneytosmoney = "不是數字型別"

exit function

end if

dim basicdwstring as string, basicdw() as string

dim moneydwstring as string, moneydw() as string

dim formatd1string as string, formatd1() as string

dim formatd2string as string, formatd2() as string

dim formatd3string as string, formatd3() as string

dim moneystr as string, returnstr as string, tempstr as string

dim pcount as long

basicdwstring = "分,角,圓,拾,佰,仟,萬,拾萬,佰萬,仟萬,億,拾億,佰億,仟億,萬億,兆,拾兆,佰兆,仟兆,萬兆,億兆"

moneydwstring = "零,壹,貳,叄,肆,伍,陸,柒,捌,玖"

formatd1string = "拾萬,佰萬,仟萬,拾億,佰億,仟億,萬億,拾兆,佰兆,仟兆,萬兆,億兆"

formatd2string = "拾,佰,仟,拾,佰,仟,萬,拾,佰,仟,萬,億"

formatd3string = "萬,萬,萬,億,億,億,億,兆,兆,兆,兆,兆"

basicdw = split(basicdwstring, ",")

moneydw = split(moneydwstring, ",")

formatd1 = split(formatd1string, ",")

formatd2 = split(formatd2string, ",")

formatd3 = split(formatd3string, ",")

moneystr = format(nmoney, "0.00")

moneystr = replace(moneystr, ".", "")

strlen = len(moneystr)

returnstr = ""

for x = 0 to strlen - 1

tempstr = mid(moneystr, strlen - x, 1)

returnstr = moneydw(tempstr) & basicdw(x) & returnstr

next x

returnstr = replace(returnstr, "零分", "")

returnstr = replace(returnstr, "零角", "")

returnstr = replace(returnstr, "零拾", "零")

returnstr = replace(returnstr, "零佰", "零")

returnstr = replace(returnstr, "零仟", "零")

returnstr = replace(returnstr, "零萬", "零")

returnstr = replace(returnstr, "零億", "零")

returnstr = replace(returnstr, "零兆", "零")

doreturnstr = replace(returnstr, "零零", "零")

loop while instr(returnstr, "零零") <> 0

returnstr = replace(returnstr, "零圓", "圓")

if right(returnstr, 1) <> "圓" then

returnstr = replace(returnstr, "圓", "零")

returnstr = returnstr & "圓"

end if

returnstr = returnstr & "整"

for x = 0 to ubound(formatd1)

pcount = instr(1, returnstr, formatd1(x), vbtextcompare)

if pcount > 0 then

if instr(pcount + 2, returnstr, formatd3(x), vbtextcompare) > 0 then

returnstr = replace(returnstr, formatd1(x), formatd2(x))

end if

end if

next x

pcount = instr(1, returnstr, "萬兆", vbtextcompare)

nmoneytosmoney = returnstr

end function

oracle中將數字金額轉換為中文大寫函式

oracle中有乙個將數字金額轉換為中文形式的內部函式 money to chinese 此方法出處 sql create or replace function money to chinese money in varchar2 return varchar2 isc money varchar...

數字金額轉換成中文金額(C 實現)

public static string convertnumamttochinese decimal numval switch j ret temp ret ret ret.replace 零拾 零 ret ret.replace 零佰 零 ret ret.replace 零仟 零 ret re...

php實現數字金額轉換成中文大寫金額

header content type text html charset utf 8 數字金額轉換成中文大寫金額的函式 string int num 要轉換的小寫數字或小寫字串 return 大寫字母 小數字為兩位 function num to rmb num i 0 c while 1 els...