Function
RMB(money)
money = FormatNumber (money, 2 ) ' 精确到小数点两位(实现角分)
Dim moneyBigList ' 零壹贰叁肆伍陆柒捌玖
Dim unitList ' 分角元拾佰仟万拾佰仟亿拾佰仟万
Dim moneystr ' 数字金额字符串(money * 100)
Dim moneyLen ' 数字金额字符串长度(money * 100)
Dim moneyChar ' 小写金额:单个位数
Dim n1, n2 ' "零壹贰叁肆伍陆柒捌玖":单个字符,"分角元拾佰仟万拾佰仟亿拾佰仟万":单个字符
Dim n ' 循环变量
Dim moneyBig ' 大写金额
moneyBigList = " 零壹贰叁肆伍陆柒捌玖 "
unitList = " 分角元拾佰仟万拾佰仟亿拾佰仟万 "
If money > 9999999999999.99 Then ' 限制最大值(99999亿9999万9999元9角9分)
rmb = " 超出范围的人民币值 "
Exit Function
End If
moneystr = CStr (money * 100 ) ' 转换成分
moneyLen = Len (moneystr) ' 获得长度
n = 1
Do While n <= moneyLen
moneyChar = CInt ( Mid (moneystr, n, 1 )) ' 小写金额:单个位数
n1 = Mid (moneyBigList, moneyChar + 1 , 1 ) ' 大写金额:单个字符
n2 = Mid (unitList, moneyLen - n + 1 , 1 ) ' 单位
If Not n1 = " 零 " Then
moneyBig = moneyBig + CStr (n1) + CStr (n2)
Else
If n2 = " 亿 " Or n2 = " 万 " Or n2 = " 元 " Or n1 = " 零 " Then
Do While Right (moneyBig, 1 ) = " 零 "
moneyBig = Left (moneyBig, Len (moneyBig) - 1 )
Loop
End If
If (n2 = " 亿 " Or (n2 = " 万 " And Right (moneyBig, 1 ) <> " 亿 " ) Or n2 = " 元 " ) Then
moneyBig = moneyBig + CStr (n2)
Else
If Left ( Right (moneyBig, 2 ), 1 ) = " 零 " Or Right (moneyBig, 1 ) <> " 亿 " Then
moneyBig = moneyBig + n1
End If
End If
End If
n = n + 1
Loop
Do While Right (moneyBig, 1 ) = " 零 " ' 去掉最右边的"零"
moneyBig = Left (moneyBig, Len (moneyBig) - 1 )
Loop
If Right (moneyBig, 1 ) = " 元 " Then ' 加上"整"
moneyBig = moneyBig + " 整 "
End If
RMB = moneyBig ' 返回大写金额
End Function
money = FormatNumber (money, 2 ) ' 精确到小数点两位(实现角分)
Dim moneyBigList ' 零壹贰叁肆伍陆柒捌玖
Dim unitList ' 分角元拾佰仟万拾佰仟亿拾佰仟万
Dim moneystr ' 数字金额字符串(money * 100)
Dim moneyLen ' 数字金额字符串长度(money * 100)
Dim moneyChar ' 小写金额:单个位数
Dim n1, n2 ' "零壹贰叁肆伍陆柒捌玖":单个字符,"分角元拾佰仟万拾佰仟亿拾佰仟万":单个字符
Dim n ' 循环变量
Dim moneyBig ' 大写金额
moneyBigList = " 零壹贰叁肆伍陆柒捌玖 "
unitList = " 分角元拾佰仟万拾佰仟亿拾佰仟万 "
If money > 9999999999999.99 Then ' 限制最大值(99999亿9999万9999元9角9分)
rmb = " 超出范围的人民币值 "
Exit Function
End If
moneystr = CStr (money * 100 ) ' 转换成分
moneyLen = Len (moneystr) ' 获得长度
n = 1
Do While n <= moneyLen
moneyChar = CInt ( Mid (moneystr, n, 1 )) ' 小写金额:单个位数
n1 = Mid (moneyBigList, moneyChar + 1 , 1 ) ' 大写金额:单个字符
n2 = Mid (unitList, moneyLen - n + 1 , 1 ) ' 单位
If Not n1 = " 零 " Then
moneyBig = moneyBig + CStr (n1) + CStr (n2)
Else
If n2 = " 亿 " Or n2 = " 万 " Or n2 = " 元 " Or n1 = " 零 " Then
Do While Right (moneyBig, 1 ) = " 零 "
moneyBig = Left (moneyBig, Len (moneyBig) - 1 )
Loop
End If
If (n2 = " 亿 " Or (n2 = " 万 " And Right (moneyBig, 1 ) <> " 亿 " ) Or n2 = " 元 " ) Then
moneyBig = moneyBig + CStr (n2)
Else
If Left ( Right (moneyBig, 2 ), 1 ) = " 零 " Or Right (moneyBig, 1 ) <> " 亿 " Then
moneyBig = moneyBig + n1
End If
End If
End If
n = n + 1
Loop
Do While Right (moneyBig, 1 ) = " 零 " ' 去掉最右边的"零"
moneyBig = Left (moneyBig, Len (moneyBig) - 1 )
Loop
If Right (moneyBig, 1 ) = " 元 " Then ' 加上"整"
moneyBig = moneyBig + " 整 "
End If
RMB = moneyBig ' 返回大写金额
End Function
'调用方法
Response.Write(RMB(1986))