<%
function changenumtodx(sourcenum)
dim string1 如下定义
dim string2 如下定义
dim string3 从原sourcenum值中取出的值
dim i 循环变量
dim j sourcenum的值乘以100的字符串长度
dim ch1 数字的汉语读法
dim ch2 数字位的汉字读法
dim nzero 用来计算连续的零值是几个
string1 = "零壹贰叁肆伍陆柒捌玖"
string2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
nzero = 0
changenumtodx=""
if not isnumeric(sourcenum) then
sourcenum="0"
end if
if instr(1, cstr(sourcenum * 100), ".") <> 0 then
err.raise 5000, , "此函数( atoc() )只能转换小数点后有两位以内的数!"
end if
j = len(cstr(sourcenum * 100))
string2 = right(string2, j) 取出对应位数的string2的值
for i = 1 to j
string3 = mid(sourcenum * 100, i, 1) 取出需转换的某一位的值
if i <> (j – 3) + 1 and i <> (j – 7) + 1 and i <> (j – 11) + 1 and i <>(j – 15) + 1 then
if string3 = 0 then
ch1 = ""
ch2 = ""
nzero = nzero + 1
elseif string3 <> 0 and nzero <> 0 then
ch1 = "零" & mid(string1, clng(string3) + 1, 1)
ch2 = mid(string2, i, 1)
nzero = 0
else
ch1 = mid(string1, clng(string3) + 1, 1)
ch2 = mid(string2, i, 1)
nzero = 0
end if
else 该位是万亿,亿,万,元位等关键位
if string3 <> 0 and nzero <> 0 then
ch1 = "零" & mid(string1, clng(string3) + 1, 1)
ch2 = mid(string2, i, 1)
nzero = 0
elseif string3 <> 0 and nzero = 0 then
ch1 = mid(string1, clng(string3) + 1, 1)
ch2 = mid(string2, i, 1)
nzero = 0
elseif string3 = 0 and nzero >= 3 then
ch1 = ""
ch2 = ""
nzero = nzero + 1
else
ch1 = ""
ch2 = mid(string2, i, 1)
nzero = nzero + 1
end if
if i = (j – 11) + 1 or i = (j – 3) + 1 then 如果该位是亿位或元位,则必须写上
ch2 = mid(string2, i, 1)
end if
end if
atoc = atoc & ch1 & ch2
if i = j and string3 = 0 then 最后一位(分)为0时,加上“整”
changenumtodx = atoc & "整"
end if
next
if sourcenum=0 then
changenumtodx="零元整"
end if
end function
以下为例子
response.write changenumtodx(100000)
结果为:壹拾万元整
%>
