|
我在去年买了 《专家门诊——ACCESS开发答疑200问》书,,其中有一篇"如何将数字金额转换中文金额"的文章,至今无法理解,我需要转整数的,不需要小数的,即:转换年限的,也就是说10年转换拾年,15年转换拾伍年的,请高手们帮帮忙!
谢谢!
下面是这篇文章的代码!
Option Compare Database
Public Function NumberToCn(I As Integer) As String
'将单个数字转为中文对应数字字符
Select Case I
Case 0
NumberToCn = "零"
Case 1
NumberToCn = "壹"
Case 2
NumberToCn = "贰"
Case 3
NumberToCn = "参"
Case 4
NumberToCn = "肆"
Case 5
NumberToCn = "伍"
Case 6
NumberToCn = "陆"
Case 7
NumberToCn = "柒"
Case 8
NumberToCn = "捌"
Case 9
NumberToCn = "玖"
End Select
End Function
Public Function AmtToCn(dblAmt As Double) As String
Const strAmt = "仟佰拾亿仟佰拾万仟佰拾元"
Dim strInt As String '整数部分
Dim strNum As String '小数部分
Dim strTemp, strTemp1 As String '临时字符串变量
Dim I As Integer, dblTemp As Double
'整理参数:保留两位小数并取绝对值
dblTemp = Abs(Round(dblAmt, 2))
'处理小数部分
If InStr(1, dblTemp, ".") <> 0 Then
strNum = Mid(dblTemp, InStr(1, dblTemp, ".") + 1, 2)
strInt = Left(dblTemp, InStr(1, dblTemp, ".") - 1)
If Len(strNum) = 1 Then
'调用自定义函数将单个数字转换为对应的中文字符
strNum = NumberToCn(Int(strNum)) & "角零分"
Else
strNum = NumberToCn(Mid(strNum, 1, 1)) & "角" & NumberToCn(Mid(strNum, 2, 1)) & "分"
End If
Else
strNum = "零角零分"
strInt = dblTemp
End If
'处理整数部分,分别取出数字并转换为中文对应字符再与中文位字符组合
strTemp = Right(strAmt, Len(strInt))
For I = 1 To Len(strInt)
strTemp1 = strTemp1 & NumberToCn(Mid(strInt, I, 1)) & Mid(strTemp, I, 1)
Next I
'判断原参数正负返回结果
If dblAmt > 0 Then
AmtToCn = strTemp1 & strNum
Else
AmtToCn = "负" & strTemp1 & strNum
End If
End Function
|
|