|
楼主 |
发表于 2019-12-16 01:28
|
显示全部楼层
中文财务及大小写数字与阿拉伯数字互转
本帖最后由 YZC51 于 2019-12-20 19:01 编辑
Public Function YZC(s, Optional Z = 0) '中文数字与阿拉伯数字互转 原创 2019-12-20
If Len(s) = 0 Then YZC = "": Exit Function
If Z = 1 Then YZC = ToN(s): Exit Function
If Z = 2 Then YZC = Application.Text(s, "[<20][dbnum1]d;[dbnum1]"): Exit Function
If Z = 3 Then YZC = Replace(Application.Text(s, "[dbnum1]"), "-", "负"): Exit Function
If Z = 4 Then YZC = Replace(Application.Text(s, "[dbnum2]"), "-", "负"): Exit Function
M = Abs(s): If M < 0.005 Then YZC = "": Exit Function
gs = "[dbnum2]"
If M >= 0.995 And M < 1 Then M = 1
g$ = IIf(M < 0.095, "", "0角")
a = IIf(M < 1, "", Application.Text(Int(Abs(M)), gs) & "元")
b = Application.Text((Abs(M) - Int(Abs(M))) * 100 + 0.01, gs & g & "0分")
c = Replace(Replace(Replace(a & b, "零分", "整"), "零角整", "整"), "零角", "零")
YZC = IIf(s < 0, "负", "") & c
End Function
Function ToN(ss) '学习大理版主的代码。谢谢老师!
If Len(ss) = 0 Then ToN = "": Exit Function
xsd = InStr(ss & ".", "."): xs = Mid(ss, xsd + 1) '中文财务及大小写数字转阿拉伯数字
ss = Mid(ss, 1, xsd - 1) & "圆"
For i% = 1 To 9
ss = Replace(ss, Mid("壹贰叁肆伍陆柒捌玖", i, 1), i) '取中文大写整数
ss = Replace(ss, Mid("一二三四五六七八九", i, 1), i) '取中文小写整数
If Len(xs) = 0 Then GoTo xx
xs = Replace(xs, Mid("壹贰叁肆伍陆柒捌玖", i, 1), i) '取中文大写小数
xs = Replace(xs, Mid("一二三四五六七八九", i, 1), i) '取中文小写小数
xx:
Next
xs = "0." & xs '合成小数
For i% = Len(ss) To 1 Step -1 '生成占位 0
s$ = Mid$(ss, i, 1)
x% = InStr("分角圆拾佰仟万 亿 兆", s)
If x = 0 Then x% = InStr(" 毛元十百千萬 億", s)
If x Then j% = IIf(j% < x, x, ((j - 3) \ 4) * 4 + x)
If Val(s) Then m# = m# + (s & String(j - 1, "0")) / 100
Next
ToN = m + xs: If InStr(ss, "-") Or InStr(ss, "负") Then ToN = -ToN
End Function
|
评分
-
2
查看全部评分
-
|