最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
货币大写转换函数的更新
时间:2022-06-30 11:51:53 编辑:袖梨 来源:一聚教程网
<%
dim a '要转换成大写的金额
dim atoc '转换之后的值
Dim String1 '如下定义
Dim String2 '如下定义
Dim String3 '从原A值中取出的值
Dim I '循环变量
Dim J 'A的值乘以100的字符串长度
Dim Ch1 '数字的汉语读法
Dim Ch2 '数字位的汉字读法
Dim nZero '用来计算连续的零值是几个
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
nZero = 0
If InStr(1, CStr(a * 100), ".") <> 0 Then
err.Raise 5000, , "此函数( AtoC() )只能转换小数点后有两位以内的数!"
End If
J = Len(CStr(a * 100))
String2 = Right(String2, J) '取出对应位数的STRING2的值
For I = 1 To J
String3 = Mid(a * 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时,加上“整”
AtoC = AtoC & "整"
End If
Next
if a=0 then
atoc="零元整"
end if
%>
dim a '要转换成大写的金额
dim atoc '转换之后的值
Dim String1 '如下定义
Dim String2 '如下定义
Dim String3 '从原A值中取出的值
Dim I '循环变量
Dim J 'A的值乘以100的字符串长度
Dim Ch1 '数字的汉语读法
Dim Ch2 '数字位的汉字读法
Dim nZero '用来计算连续的零值是几个
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
nZero = 0
If InStr(1, CStr(a * 100), ".") <> 0 Then
err.Raise 5000, , "此函数( AtoC() )只能转换小数点后有两位以内的数!"
End If
J = Len(CStr(a * 100))
String2 = Right(String2, J) '取出对应位数的STRING2的值
For I = 1 To J
String3 = Mid(a * 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时,加上“整”
AtoC = AtoC & "整"
End If
Next
if a=0 then
atoc="零元整"
end if
%>
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20