程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 數字金額變大寫

數字金額變大寫

編輯:.NET實例教程

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 = ""

$False$

            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 += "億"
 &nbsp;                  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
&nbsp;           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 Function
End Class
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved