ASP 版:
<%
'文 件 名:cmycur.asp
'作 者:二十四画生
'版 本:1.0
'简 介:转换函数文件。
'功能描述:转换货币形式的函数。(该文件包含两个函数,一个转换成一般货币形式cmycur(num),一个转换成大写形式cmycurd(num))
%>
<%
function cmycur(num) '转换为货币形式如:¥180.00元
dim thenum
if isnull(num) or num = "" then
cmycur = " "
else
num = Round(num,2)
thenum = FormatCurrency(num,2,-1)
cmycur = thenum & "元"
end if
end function
function cmycurd(num) 'num为要转换成大写的金额
dim str1 '如下定义
dim str2 '如下定义
dim str3 '从原num值中取出的值
dim i '循环变量
dim j 'num的值乘以100的字符串长度
dim ch1 '数字的汉语读法
dim ch2 '数字位的汉字读法
dim nzero '用来计算连续的零值是几个
str1 = "零壹贰叁肆伍陆柒捌玖"
str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
nzero = 0
if isnull(num) or num = "" then
cmycurd = " "
exit function
end if
num = Round(Abs(num),2) '将num取绝对值并四舍五入取2位小数
j = Len(CStr(num * 100)) '找出最高位
if j > 15 then
cmycurd = "溢出"
exit function
end if
str2 = Right(str2, j) '取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分
'循环取出每一位需要转换的值
for i = 1 to j
str3 = Mid(num * 100, i, 1) '取出需转换的某一位的值
if i <> (j - 3) + 1 and i <> (j - 7) + 1 and i <> (j - 11) + 1 and i <>(j - 15) + 1 then '当所取位数不为元、万、亿、万亿上的数字时<