金額大小寫轉(zhuǎn)換的asp完全無錯(cuò)版本
當(dāng)前位置:點(diǎn)晴教程→知識管理交流
→『 技術(shù)文檔交流 』
[align=left]
[p]<!--#include file=common.asp-->[br]<%[br]dim tmpnum[br]'從第一張頁面?zhèn)鬟^來的小寫金額[br]tmpnum=request("page1num")[br]'調(diào)用并顯示大寫金額[br]response.write rmb(cdbl(tmpnum))[br]response.end[br]%>[/p] [p][br]common.asp[br]<%[br]function rmb(num)[/p] [p]num = formatnumber(num, 2)[br]dim numlist [br]dim rmblist [br]dim numlen[br]dim numchar[br]dim numstr[br]dim n [br]dim n1, n2 [br]dim hz[br]numlist = "零壹貳叁肆伍陸柒捌玖"[br]rmblist = "分角元拾佰仟萬拾佰仟億拾佰仟萬"[/p] [p]if num > 9999999999999.99 then[br] rmb = "超出范圍的人民幣值"[br] exit function[br]end if[/p] [p]numstr = cstr(num * 100)[br]numlen = len(numstr)[br]n = 1[br]do while n <= numlen[br] numchar = cint(mid(numstr, n, 1))[br] n1 = mid(numlist, numchar + 1, 1)[br] n2 = mid(rmblist, numlen - n + 1, 1)[br] if not n1 = "零" then[br] hz = hz + cstr(n1) + cstr(n2)[br] else[br] if n2 = "億" or n2 = "萬" or n2 = "元" or n1 = "零" then[br] do while right(hz, 1) = "零"[br] hz = left(hz, len(hz) - 1)[br] loop[br] end if[br] if (n2 = "億" or (n2 = "萬" and right(hz, 1) <> "億") or n2 = "元") then[br] hz = hz + cstr(n2)[br] else[br] if left(right(hz, 2), 1) = "零" or right(hz, 1) <> "億" then[br] hz = hz + n1[br] end if[br] end if[br] end if[br] n = n + 1[br]loop[br]do while right(hz, 1) = "零"[br] hz = left(hz, len(hz) - 1)[br]loop[br]if right(hz, 1) = "元" then[br] hz = hz + "整"[br]end if[br]rmb = hz[br]end function[/p] [p]%>[/p] [p][br]這個(gè)版本解決了小數(shù)位不能到分的問題,處理方式符合會(huì)計(jì)方式![/p][/align] 該文章在 2010/6/27 17:20:15 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |