kerrypnx
2/8/2018 - 6:23 AM

人民币大小写:2018-2-8

人民币大小写:2018-2-8

Function 人民币大写(M)
y = Int(Round(100 * Abs(M)) / 100)
j = Round(100 * Abs(M) + 0.00001) - y * 100
f = Round((j / 10 - Int(j / 10)) * 10)
A = IIf(y < 1, "", Application.Text(y, "[DBNum2]") & "元")
b = IIf(j > 9.4, Application.Text(Int(j / 10), "[DBNum2]") & "角", IIf(y < 1, "", IIf(f > 0.4, "零", "")))
c = IIf(f < 1, "整", Application.Text(Round(f, 0), "[DBNum2]") & "分")
人民币大写 = IIf(Abs(M) < 0.005, "", IIf(M < 0, "负" & A & b & c, A & b & c))
End Function

Function DxToN(ss)
    For i% = 1 To 9
        ss = Replace(ss, Mid("壹贰叁肆伍陆柒捌玖", i, 1), i)
        ss = Replace(ss, Mid("一二三四五六七八九", i, 1), i)
    Next
    For i% = Len(ss) To 1 Step -1
        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
    DxToN = Round(M, 2)
    If InStr(ss, "-") Or InStr(ss, "负") Then DxToN = -DxToN
End Function