金额大小写转换的asp完全无错版本
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[align=left]
[p]<!--#include file=common.asp-->[br]<%[br]dim tmpnum[br]'从第一张页面传过来的小写金额[br]tmpnum=request("page1num")[br]'调用并显示大写金额[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]这个版本解决了小数位不能到分的问题,处理方式符合会计方式![/p][/align] 该文章在 2010/6/27 17:20:15 编辑过 |
关键字查询
相关文章
正在查询... |