貨幣大寫轉換函數(shù)的更新
發(fā)表時間:2023-08-13 來源:明輝站整理相關軟件相關文章人氣:
[摘要]<%dim a '要轉換成大寫的金額dim atoc '轉換之后的值Dim String1 '如下定義Dim String2 '如下定義Dim String3 ...
<%
dim a '要轉換成大寫的金額
dim atoc '轉換之后的值
Dim String1 '如下定義
Dim String2 '如下定義
Dim String3 '從原A值中取出的值
Dim I '循環(huán)變量
Dim J 'A的值乘以100的字符串長度
Dim Ch1 '數(shù)字的漢語讀法
Dim Ch2 '數(shù)字位的漢字讀法
Dim nZero '用來計算連續(xù)的零值是幾個
String1 = "零壹貳叁肆伍陸柒捌玖"
String2 = "萬仟佰拾億仟佰拾萬仟佰拾元角分"
nZero = 0
If InStr(1, CStr(a * 100), ".") <> 0 Then
err.Raise 5000, , "此函數(shù)( AtoC() )只能轉換小數(shù)點后有兩位以內的數(shù)!"
End If
J = Len(CStr(a * 100))
String2 = Right(String2, J) '取出對應位數(shù)的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
%>