数字金额变大写

来源:互联网 发布:汉服复原小组淘宝店 编辑:程序博客网 时间:2024/04/30 07:18

Public Class Class1    Dim strbig(10) As String    Dim strUnit(6) As String    Private Function SmallToBig(ByVal Number As Decimal) As String        Try            strbig(0) = "零"            strbig(1) = "壹"            strbig(2) = "贰"            strbig(3) = "叁"            strbig(4) = "肆"            strbig(5) = "伍"            strbig(6) = "陆"            strbig(7) = "柒"            strbig(8) = "捌"            strbig(9) = "玖"            strbig(10) = "拾"

            strUnit(0) = ""            strUnit(1) = "拾"            strUnit(2) = "佰"            strUnit(3) = "千"            strUnit(4) = "万"            strUnit(5) = "亿"            strUnit(6) = "兆"

            Dim strNumber As String = Number.ToString            Dim strend As String = ""

            If strNumber.IndexOf(".") > -1 Then                strNumber = strNumber.Substring(0, strNumber.IndexOf("."))                strend = Number.ToString.Replace(strNumber, "").Replace(".", "")            End If            Dim count As Integer = 0            Dim rNumber As String = ""            Dim str As String = ""            Do While (Math.Floor(strNumber.Length / 4) - count) >= 0                str = _fourNumber(strNumber.Substring(IIf(strNumber.Length - (count + 1) * 4 < 0, 0, strNumber.Length - (count + 1) * 4), IIf(strNumber.Length - (count + 1) * 4 < 0, strNumber.Length - count * 4, 4)))                If count = 1 Then                    If str.Length <> 0 Then                        str += "万"                    End If                ElseIf count = 2 Then                    If str.Length <> 0 Then                        str += "亿"                    End If                ElseIf count >= 3 Then                    If str.Length <> 0 Then                        str += "兆"                    End If                End If                rNumber = str + rNumber                count += 1            Loop

            '小数            If strend.Length = 1 Then                strend = strbig(CInt(strend)) + "角"            ElseIf strend.Length = 2 Then                If CInt(strend).ToString.Length = 1 Then                    strend = strbig(CInt(strend)) + "分"                Else                    strend = strbig(CInt(strend.Substring(0, 1))) + "角" + strbig(CInt(strend.Substring(1, 1))) + "分"                End If            End If

            Return rNumber + "元" + strend        Catch ex As Exception            Return ""        End Try    End Function    Private Function _fourNumber(ByVal strNum As String) As String        Try            Dim count As Integer = 0            Dim i As Integer            Dim rNum As String = ""            Dim str As String = ""            For i = strNum.Length - 1 To 0 Step -1                str = strbig(strNum.Substring(i, 1))                If str = "零" Then                    rNum = str + rNum                Else                    rNum = str + strUnit(count) + rNum                End If                count += 1            Next            Do While rNum.IndexOf("零零") > -1                rNum = rNum.Replace("零零", "零")            Loop            If Microsoft.VisualBasic.Right(rNum, 1) = "零" Then                rNum = rNum.Substring(0, rNum.Length - 1)            End If            Return rNum        Catch ex As Exception            Return ""        End Try    End FunctionEnd Class 

原创粉丝点击