65.9K
CodeProject 正在变化。 阅读更多。
Home

将数字转换为单词

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.98/5 (33投票s)

2008年2月20日

CPOL
viewsIcon

206785

downloadIcon

11052

使用 VB.NET 将任何十进制数转换为文字。

引言

我创建了这个函数用于将金额转换为印度卢比 (INR)。您可以根据需要进行操作,例如小数设置、美元(任何货币)前缀。

背景

我根据客户的要求编写了这个函数,用于打印账单金额的文字格式。

使用代码

这个二维数组存储数字的主要文字转换。

     Function retWord(ByVal Num As Decimal) As String
        'This two dimensional array store the primary word convertion of number.
        retWord = ""
        Dim ArrWordList(,) As Object = {{0, ""}, {1, "One"}, {2, "Two"}, {3, "Three"}, {4, "Four"}, _
                                        {5, "Five"}, {6, "Six"}, {7, "Seven"}, {8, "Eight"}, {9, "Nine"}, _
                                        {10, "Ten"}, {11, "Eleven"}, {12, "Twelve"}, {13, "Thirteen"}, {14, "Fourteen"}, _
                                        {15, "Fifteen"}, {16, "Sixteen"}, {17, "Seventeen"}, {18, "Eighteen"}, {19, "Nineteen"}, _
                                        {20, "Twenty"}, {30, "Thirty"}, {40, "Forty"}, {50, "Fifty"}, {60, "Sixty"}, _
                                        {70, "Seventy"}, {80, "Eighty"}, {90, "Ninety"}, {100, "Hundred"}, {1000, "Thousand"}, _
                                        {100000, "Lakh"}, {10000000, "Crore"}}

        Dim i As Integer
        For i = 0 To UBound(ArrWordList)
            If Num = ArrWordList(i, 0) Then
                retWord = ArrWordList(i, 1)
                Exit For
            End If
        Next
        Return retWord
    End Function
        

© . All rights reserved.