金额大小写转换的asp完全无错版本
<!--#include file=common.-->
<%
dim tmpnum
从第一张页面传过来的小写金额
tmpnum=request("page1num")
调用并显示大写金额
response.write rmb(cdbl(tmpnum))
response.end
%>
common.asp
<%
function rmb(num)
num = formatnumber(num, 2)
dim numlist
dim rmblist
dim numlen
dim numchar
dim numstr
dim n
dim n1, n2
dim hz
numlist = "零壹贰叁肆伍陆柒捌玖"
rmblist = "分角元拾佰仟万拾佰仟亿拾佰仟万"
if num > 9999999999999.99 then
rmb = "超出范围的人民币值"
exit function
end if
numstr = cstr(num * 100)
numlen = len(numstr)
n = 1
do while n <= numlen
numchar = cint(mid(numstr, n, 1))
n1 = mid(numlist, numchar + 1, 1)
n2 = mid(rmblist, numlen - n + 1, 1)
if not n1 = "零" then
hz = hz + cstr(n1) + cstr(n2)
else
if n2 = "亿" or n2 = "万" or n2 = "元" or n1 = "零" then
do while right(hz, 1) = "零"
hz = left(hz, len(hz) - 1)
loop
end if
if (n2 = "亿" or (n2 = "万" and right(hz, 1) <> "亿") or n2 = "元") then
hz = hz + cstr(n2)
else
if left(right(hz, 2), 1) = "零" or right(hz, 1) <> "亿" then
hz = hz + n1
end if
end if
end if
n = n + 1
loop
do while right(hz, 1) = "零"
hz = left(hz, len(hz) - 1)
loop
if right(hz, 1) = "元" then
hz = hz + "整"
end if
rmb = hz
end function
%>
这个版本解决了小数位不能到分的问题,处理方式符合会计方式!
上一篇: 站外推广有哪些?你知道Deal吗?
下一篇: Java异常