Public Function GetCapital(szNumber As String) As String
    Dim aszUnit(2, 10) As String
    aszUnit(0, 0) = "圆"
    aszUnit(0, 1) = "拾"
    aszUnit(0, 2) = "佰"
    aszUnit(0, 3) = "仟"
    aszUnit(0, 4) = "万"
    aszUnit(0, 5) = "亿"
    aszUnit(0, 6) = "兆"
    aszUnit(0, 7) = "吉"
    aszUnit(0, 8) = "分"
    aszUnit(0, 9) = "角"
    aszUnit(1, 0) = "零"
    aszUnit(1, 1) = "壹"
    aszUnit(1, 2) = "贰"
    aszUnit(1, 3) = "叁"
    aszUnit(1, 4) = "肆"
    aszUnit(1, 5) = "伍"
    aszUnit(1, 6) = "陆"
    aszUnit(1, 7) = "柒"
    aszUnit(1, 8) = "捌"
    aszUnit(1, 9) = "玖"    Dim szResult As String
    szResult = "人民币:"
    Dim szBefore As String, szEnd As String
    Dim nPix As Integer
    nPix = InStr(szNumber, ".")
    If nPix = 0 Then
        szBefore = szNumber
        szEnd = ""
    Else
        szBefore = Left(szNumber, nPix - 1)
        szEnd = Right(szNumber, Len(szNumber) - nPix)
    End If
    
    Dim nLength As Integer
    
    nLength = Len(szBefore)    Dim i As Integer
    Dim nUnit As Integer
    For i = 1 To nLength
        Dim nTempLen As Integer
        nTempLen = nLength - i        If (nTempLen Mod 4) = 0 Then
            If nTempLen <> 0 Then
                nUnit = 4 + nTempLen / 4 - 1
            Else
                nUnit = 0
            End If
        Else
            nUnit = nTempLen Mod 4
        End If
        
        szResult = szResult & aszUnit(1, Asc(Mid(szBefore, i, 1)) - 48)
        
        szResult = szResult & aszUnit(0, nUnit)
        
    Next i    If szEnd = "" Then
        szResult = szResult & "整"
        GetCapital = szResult
        Exit Function
    End If
    
    nLength = Len(szEnd)
    
    For i = 1 To nLength        nUnit = nLength - i + 7
        
        szResult = szResult & aszUnit(1, Asc(Mid(szEnd, i, 1)) - 48)
        
        szResult = szResult & aszUnit(0, nUnit + 1)
    Next i
    
    GetCapital = szResult
End Function

解决方案 »

  1.   

    '*********************************************************
    '* 名称:nNumber2Chinese
    '* 功能:数值转换为人民币(汉字)
    '* 用法:nNumber2Chinese(数值)
    '*********************************************************
    Public Function Num2Chi(txtJE As Double) As String
        Dim i, K As Integer
        Dim NC, nd, ka, chrNum, strZheng As String
        Dim c1, c2, c3 As String
        Dim K1 As Integer
        Dim Zheng As String
        Dim Xiao As String
        NC = Trim(Format(txtJE, "##0.00"))
        c1 = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元"
        c2 = "角分"
        c3 = "玖捌柒陆伍肆叁贰壹"
        If NC = 0 Then
            Num2Chi = "零元整"
            Exit Function
        End If
        Num2Chi = ""
        Zheng = Mid(NC, 1, (Len(NC) - 3))
        Xiao = Mid(NC, (Len(Zheng) + 2))
        If Val(Xiao) <> 0 Then
            For i = Len(Xiao) To 1 Step -1
                chrNum = Mid(Xiao, i, 1)
                If chrNum <> 0 Then
                    Num2Chi = Mid(c2, i, 1) & Num2Chi
                    Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
                End If
            Next i
        End If
        
        K = 0
        If Val(Zheng) <> 0 Then
            Num2Chi = "元" & Num2Chi
            For i = Len(Zheng) To 1 Step -1
                If (Len(Zheng) - i) = 4 Then
                    Num2Chi = "万" & Num2Chi
                ElseIf (Len(Zheng) - i) = 8 Then
                    Num2Chi = "亿" & Num2Chi
                ElseIf (Len(Zheng) - i) = 12 Then
                    Num2Chi = "万" & Num2Chi
                End If
                chrNum = Mid(Zheng, i, 1)
                If chrNum <> 0 Then
                    If i = Len(Zheng) Then
                        Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
                    Else
                        If (Len(Zheng) - i) <> 4 And (Len(Zheng) - i) <> 8 And (Len(Zheng) - i) <> 12 Then
                            Num2Chi = Mid(c1, (Len(c1) - K), 1) & Num2Chi
                        End If
                        Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
                    End If
                Else
                    If Mid(Num2Chi, 1, 1) <> "元" And Mid(Num2Chi, 1, 1) <> "万" And Mid(Num2Chi, 1, 1) <> "亿" Then
                        If Mid(Num2Chi, 1, 1) <> "零" Then
                            Num2Chi = "零" & Num2Chi
                        End If
                    End If
               End If
                K = K + 1
            Next i
        End If
        If Right(Trim(Num2Chi), 1) <> "分" Then
            Num2Chi = Num2Chi & "整"
        End If
    End Function