用于将数字换汉字大写数字的函数
时间:2006-10-23 21:52 来源:Access开发者 作者:goodorba… 阅读:次
正文:
'用于将数字换汉字大写数字的函数
Function zhh(mrmbze)
Dim S_1 As String
Dim S_2 As String
Dim S_4 As String
Dim s_5 As String
Dim S_6 As String
Dim S_7 As String
Dim I As Integer
Dim tn As Single
S_1 = "零壹贰叁肆伍陆柒捌玖"
S_2 = "仟佰拾万仟佰拾元角分"
Option Compare Database
Option Explicit
Function CWord(myNumber As Double) As String
Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String, str7 As String
Dim I As Integer, J As Integer, K As Integer, L As Integer
str1 = "仟佰拾亿仟佰拾万仟佰拾元角分"
str2 = "元角分"
str3 = "零壹贰叁肆伍陆柒捌玖"
str4 = Left(Trim(Format(myNumber, "0.00")), Len(Format(myNumber, "0.00")) - 3) & Right(Trim(Format(myNumber, "0.00")), 2)
str5 = Right(Trim(Format(myNumber, "0.00")), 2)
str6 = Right(str1, Len(str4))
For I = 1 To Len(str4)
K = CDbl(Mid(str4, I, 1))
str7 = str7 & Mid(str3, K + 1, 1) & Mid(str6, I, 1)
Next I
CWord = str7 & "整"
End Function
Function ctest()
MsgBox CWord(120001.03)
End Function
S_4 = Ltrim(Str(Nz(Int(mrmbze * 100))))
If Len(S_4) > 10 And mrmbze > 0 And mrmbze < 99999999.99 Then
tn = Int(mrmbze * 100) / 100
If mrmbze - tn >= 0.005 Then
tn = tn + 0.01
End If
S_4 = Ltrim(Str(tn * 100))
End If
If Len(S_4) > 10 Or mrmbze < 0 Then
zhh = "ERROR!!! The number to be transferred CANNOT be negative and must be less than 99999999.99"
Else
S_4 = String(10 - Len(S_4), " ") + S_4
I = 1
zhh = ""
Do While I <= 10
s_5 = Mid(S_4, I, 1)
If s_5 <> " " Then
S_6 = Mid(S_1, Val(s_5) + 1, 1)
S_7 = Mid(S_2, I, 1)
If s_5 = "0" And I <> 4 And I <> 8 Then
S_7 = ""
End If
If (Mid(S_4, I, 2) = "00") Or (s_5 = "0" And (I = 4 Or I = 8 Or I = 10)) Then
S_6 = ""
End If
zhh = zhh + S_6 + S_7
If Mid(S_4, I, 1) = "0" And Mid(S_4, I + 1, 1) <> "0" And (I = 4 Or I = 8) Then
zhh = zhh + "零"
End If
End If
I = I + 1
Loop
If s_5 = "0" Then
zhh = zhh + "整"
End If
End If
If zhh Like "*" & "元零" & "*" & "角" & "*" Then
zhh = Replace(zhh, "元零", "元")
End If
End Function
'用于将数字换汉字大写数字的函数
Function zhh(mrmbze)
Dim S_1 As String
Dim S_2 As String
Dim S_4 As String
Dim s_5 As String
Dim S_6 As String
Dim S_7 As String
Dim I As Integer
Dim tn As Single
S_1 = "零壹贰叁肆伍陆柒捌玖"
S_2 = "仟佰拾万仟佰拾元角分"
Option Compare Database
Option Explicit
Function CWord(myNumber As Double) As String
Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String, str7 As String
Dim I As Integer, J As Integer, K As Integer, L As Integer
str1 = "仟佰拾亿仟佰拾万仟佰拾元角分"
str2 = "元角分"
str3 = "零壹贰叁肆伍陆柒捌玖"
str4 = Left(Trim(Format(myNumber, "0.00")), Len(Format(myNumber, "0.00")) - 3) & Right(Trim(Format(myNumber, "0.00")), 2)
str5 = Right(Trim(Format(myNumber, "0.00")), 2)
str6 = Right(str1, Len(str4))
For I = 1 To Len(str4)
K = CDbl(Mid(str4, I, 1))
str7 = str7 & Mid(str3, K + 1, 1) & Mid(str6, I, 1)
Next I
CWord = str7 & "整"
End Function
Function ctest()
MsgBox CWord(120001.03)
End Function
S_4 = Ltrim(Str(Nz(Int(mrmbze * 100))))
If Len(S_4) > 10 And mrmbze > 0 And mrmbze < 99999999.99 Then
tn = Int(mrmbze * 100) / 100
If mrmbze - tn >= 0.005 Then
tn = tn + 0.01
End If
S_4 = Ltrim(Str(tn * 100))
End If
If Len(S_4) > 10 Or mrmbze < 0 Then
zhh = "ERROR!!! The number to be transferred CANNOT be negative and must be less than 99999999.99"
Else
S_4 = String(10 - Len(S_4), " ") + S_4
I = 1
zhh = ""
Do While I <= 10
s_5 = Mid(S_4, I, 1)
If s_5 <> " " Then
S_6 = Mid(S_1, Val(s_5) + 1, 1)
S_7 = Mid(S_2, I, 1)
If s_5 = "0" And I <> 4 And I <> 8 Then
S_7 = ""
End If
If (Mid(S_4, I, 2) = "00") Or (s_5 = "0" And (I = 4 Or I = 8 Or I = 10)) Then
S_6 = ""
End If
zhh = zhh + S_6 + S_7
If Mid(S_4, I, 1) = "0" And Mid(S_4, I + 1, 1) <> "0" And (I = 4 Or I = 8) Then
zhh = zhh + "零"
End If
End If
I = I + 1
Loop
If s_5 = "0" Then
zhh = zhh + "整"
End If
End If
If zhh Like "*" & "元零" & "*" & "角" & "*" Then
zhh = Replace(zhh, "元零", "元")
End If
End Function
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
相关内容
最新内容
推荐内容