|
给你修改成函数了:
'***********************************代码开始***********************************
Public Function CMoneyToCnCap(Money As Double) As String
On Error GoTo CMoneyToCnCap_Err
Dim strTemp As String
Dim intDigit As Integer
Dim strCnTempDigit As String
Dim strCnTemp As String
Dim intLen As Integer
Dim i As Integer
Dim strCnTempNum As String
Dim strDeno As String
If Money > (1 * 10 ^ 13) Or Money < (-1 * 10 ^ 13) Then
MsgBox "输入的数值的整数位数不能超过 13 位。", vbOKOnly
Exit Function
End If
strCnTempNum = "零壹贰叁肆伍陆柒捌玖拾"
strDeno = "分角元拾佰仟万拾佰仟亿拾佰仟万拾佰"
strTemp = CStr(Abs(Round(Money, 2) * 100))
intLen = Len(strTemp)
If Money = 0 Then
CMoneyToCnCap = "零元整"
Exit Function
End If
For i = intLen To 1 Step -1
intDigit = Mid(strTemp, intLen - i + 1, 1)
strCnTempDigit = Mid(strCnTempNum, intDigit + 1, 1)
strCnTemp = strCnTemp & strCnTempDigit & Mid(strDeno, i, 1)
Next
strCnTemp = Replace(strCnTemp, "零拾", "零")
strCnTemp = Replace(strCnTemp, "零佰", "零")
strCnTemp = Replace(strCnTemp, "零仟", "零")
strCnTemp = Replace(strCnTemp, "零零零", "零")
strCnTemp = Replace(strCnTemp, "零零", "零")
strCnTemp = Replace(strCnTemp, "零角零分", "整")
strCnTemp = Replace(strCnTemp, "零分", "整")
strCnTemp = Replace(strCnTemp, "零角", "零")
strCnTemp = Replace(strCnTemp, "零亿零万", "亿")
strCnTemp = Replace(strCnTemp, "零亿零万零元", "亿元")
strCnTemp = Replace(strCnTemp, "亿零万零元", "亿元")
strCnTemp = Replace(strCnTemp, "零亿零万", "亿")
strCnTemp = Replace(strCnTemp, "零万零元", "万元")
strCnTemp = Replace(strCnTemp, "万零元", "万元")
strCnTemp = Replace(strCnTemp, "零亿", "亿")
strCnTemp = Replace(strCnTemp, "零万", "万")
strCnTemp = Replace(strCnTemp, "零元", "元")
strCnTemp = Replace(strCnTemp, "零零", "零")
If Money > 0 Then
CMoneyToCnCap = strCnTemp
Else
CMoneyToCnCap = "负" & strCnTemp
End If
CMoneyToCnCap_Exit:
Exit Function
CMoneyToCnCap_Err:
MsgBox Err.Description
Resume CMoneyToCnCap_Exit
End Function
'***********************************代码结束***********************************
|
|