您的位置:首页 > 编程语言 > VB

VB阿拉伯数字金额转大写中文

2017-12-23 21:12 681 查看
Function mychange(ByVal Myinput)

    Dim Temp, TempA, MyinputA, MyinputB, MyinputC

    Dim Place As String

    Dim J As Integer

    Place = "分角元拾佰仟万拾佰仟亿拾佰仟万"

    shuzi1 = "壹贰叁肆伍陆柒捌玖"

    shuzi2 = "整零元零零零万零零零亿零零零万"

    

    qianzhui = ""

    If Val(Myinput) = 0 Then Myinput = 0

    If Myinput = "" Then Myinput = 0

    If Myinput < 0 Then qianzhui = "负"

    Myinput = Int(Abs(Myinput) * 100 + 0.5)

    If Myinput > 999999999999999# Then

      mychange = "数字太大了吧???"

      Exit Function

    End If

    If Myinput = 0 Then

      mychange = "零元零分"

      Exit Function

    End If

    

    MyinputA = Trim(Str(Myinput))

    shuzilong = Len(MyinputA)

    For J = 1 To shuzilong

    MyinputB = Mid(MyinputA, J, 1) & MyinputB

    Next

    For J = 1 To shuzilong

      Temp = Val(Mid(MyinputB, J, 1))

      If Temp = 0 Then

         MyinputC = Mid(shuzi2, J, 1) & MyinputC

      Else

         MyinputC = Mid(shuzi1, Temp, 1) & Mid(Place, J, 1) & MyinputC

      End If

    Next

    

    shuzilong = Len(MyinputC)

    For J = 1 To shuzilong - 1

      If Mid(MyinputC, J, 1) = "零" Then

         Select Case Mid(MyinputC, J + 1, 1)

            Case "零", "元", "万", "亿", "整":

            MyinputC = Left(MyinputC, J - 1) & Mid(MyinputC, J + 1, 30)

            J = J - 1

         End Select

      End If

    Next

    

    shuzilong = Len(MyinputC)

    For J = 1 To shuzilong - 1

       If Mid(MyinputC, J, 1) = "亿" And Mid(MyinputC, J + 1, 1) = "万" Then

         MyinputC = Left(MyinputC, J) & Mid(MyinputC, J + 2, 30)

         Exit For

       End If

    Next

    

    mychange = qianzhui & Trim(MyinputC)

    

End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: