[align=left]
<!--#include file=common.asp-->
<%
dim tmpnum
'從第一張頁面?zhèn)鬟^來的小寫金額
tmpnum=request("page1num")
'調(diào)用并顯示大寫金額
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
%>
這個(gè)版本解決了小數(shù)位不能到分的問題,處理方式符合會(huì)計(jì)方式!
[/align]
該文章在 2010/6/27 17:20:15 編輯過