分类:
2009-06-24 12:09:57
Public Function dx(n)
dx = Replace(Application.Text(Round(n+0.00000001, 2), "[DBnum2]"), ".", "元")
dx = IIf(Left(Right(dx, 3), 1) = "元", Left(dx, Len(dx) - 1) & "角" & Right(dx, 1) & "分", IIf(Left(Right(dx, 2), 1) = "元", dx & "角整", IIf(dx = "零", "", dx & "元整")))
dx = Replace(Replace(Replace(Replace(dx, "零元零角", ""), "零元", ""), "零角", "零"), "-", "负")
End Function
AtoC = Replace(AtoC, "拾零万", "拾万零")
Function AtoC(a As Currency) As String
' 定义两个字符串,A的值最多是两位小数,
Dim String1 As String
' 如下定义
Dim String2 As String
' 如下定义
Dim String3 As String
' 从原A值中取出的值
Dim I As Integer
' 循环变量
Dim J As Integer
' A的值乘以100的字符串长度
Dim Ch1 As String
' 数字的汉语读法
Dim Ch2 As String
' 数字位的汉字读法
Dim nZero As Integer
' 用来计算连续的非零数是几个
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
'MsgBox CStr(a * 100)
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 String3 <> "0" Then
Ch1 = Mid(String1, Val(String3) + 1, 1)
Ch2 = Mid(String2, I, 1)
nZero = nZero + 1
' 表示本位不为零
Else
If nZero <> 0 Or I = J - 9 Or I = J - 5 Or I = J - 1 Then
If Right(AtoC, 1) = "零" Then AtoC = Left(AtoC, Len(AtoC) - 1)
Ch1 = "零"
Else
Ch1 = ""
End If
If I = J - 10 Then
' 如果转换的数值需要扩大,则要改动以下表达式 I 的值
Ch2 = "亿"
ElseIf I = J - 6 Then
If nZero <> 0 Then
Ch2 = "万"
' nZero = 0
End If
ElseIf I = J - 2 Then
Ch2 = "元"
ElseIf I = J Then
Ch2 = "整"
Else
Ch2 = ""
End If
nZero = 0
End If
AtoC = AtoC & Ch1 & Ch2
Next I
AtoC = Replace(AtoC, "拾零万", "拾万零")
AtoC = Replace(AtoC, "零元", "元")
AtoC = Replace(AtoC, "零万", "万")
AtoC = Replace(AtoC, "零亿", "亿")
AtoC = Replace(AtoC, "零整", "整")
' 以上将多余的零去掉
If a > 999999 Then
AtoC = Replace(AtoC, "壹佰元整", "壹佰万元整")
AtoC = Replace(AtoC, "贰佰元整", "贰佰万元整")
AtoC = Replace(AtoC, "叁佰元整", "叁佰万元整")
AtoC = Replace(AtoC, "肆佰元整", "肆佰万元整")
AtoC = Replace(AtoC, "伍佰元整", "伍佰万元整")
AtoC = Replace(AtoC, "陆佰元整", "陆佰万元整")
AtoC = Replace(AtoC, "柒佰元整", "柒佰万元整")
AtoC = Replace(AtoC, "捌佰元整", "捌佰万元整")
AtoC = Replace(AtoC, "玖佰元整", "玖佰万元整")
End If
End Function