|
再分享两个自定义函数(不是我写的):
Function NtoC(n) 'n as single
Const cNum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分"
Const cCha = "零仟零佰零拾零零零零零亿零万零元亿万零角零分零整-零零零零零亿万元亿零整整"
NtoC = ""
sNum = Trim(Str(Int(n * 100)))
For I = 1 To Len(sNum) '逐位转换
NtoC = NtoC + Mid(cNum, (Mid(sNum, I, 1)) + 1, 1) + Mid(cNum, 26 - Len(sNum) + I, 1)
Next
For I = 0 To 11 '去掉多余的零
NtoC = Replace(NtoC, Mid(cCha, I * 2 + 1, 2), Mid(cCha, I + 26, 1))
Next
End Function
Public Function BigNum(小写数字 As Double) '将数字转为中文大写金额(本函数根据网络上的代码改编)
Application.Volatile
If 小写数字 = 0 Then
BigNum = "零元整"
Else
Const cNum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分"
Const cCha = "零仟零佰零拾零零零零零亿零万零元亿万零角零分零整-零零零零零亿万元亿零整整"
BigNum = ""
sNum = Round(Abs(小写数字), 2) * 100
For I = 1 To Len(sNum) '逐位转换
BigNum = BigNum + Mid(cNum, (Mid(sNum, I, 1)) + 1, 1) + Mid(cNum, 26 - Len(sNum) + I, 1)
Next
For I = 0 To 11 '去掉多余的零
BigNum = Replace(BigNum, Mid(cCha, I * 2 + 1, 2), Mid(cCha, I + 26, 1))
Next
If 小写数字 < 0 Then
BigNum = "负" & BigNum
End If
End If
End Function |
|