Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting number to string representation
Message
From
27/04/2009 20:25:52
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01396542
Message ID:
01396594
Views:
67
>See if this is it http://www.devx.com/vb2themax/Tip/19053

I do not know if you tried that but that doesn't work at all. When I first look at it, I said: "Wow, this is the most amazing simplified version of such logic I have ever seen.". But, it requires a lot of adjustments.

I have tried to adjust it a little bit and so far, I have this:
    Private Function NumberToWords(ByVal tnValue As Long, _
     Optional ByVal BlankIfZero As Boolean = False) As String
        Dim lcNumberToWords As String = ""

        Select Case tnValue

            Case 0
                lcNumberToWords = IIf(BlankIfZero, "", "Zero")

            Case 1 To 19
                lcNumberToWords = Choose(tnValue, "One", "Two", "Three", "Four", _
                 "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", _
                 "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
                 "Seventeen", "Eighteen", "Nineteen")

            Case 20 To 99
                lcNumberToWords = Choose(tnValue \ 10 - 1, "Twenty", "Thirty", _
                 "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", _
                 "Ninety") & NumberToWords(tnValue Mod 10, True)

            Case 100 To 999
                lcNumberToWords = NumberToWords(tnValue \ 100) & "Hundred" & IIf _
                 (tnValue >= 200, "s", "") & NumberToWords(tnValue Mod 100, True)

            Case 1000 To 999999
                lcNumberToWords = NumberToWords(tnValue \ 1000) & "Thousand" & IIf _
                 (tnValue >= 2000, "s", "") & NumberToWords(tnValue Mod 1000, True)

            Case 1000000 To 999999999
                lcNumberToWords = NumberToWords(tnValue \ 1000000) & "Million" & IIf _
                 (tnValue >= 2000000, "s", "") & NumberToWords(tnValue Mod 1000000, True)

            Case Is >= 1000000000
                lcNumberToWords = NumberToWords(tnValue \ 1000000000) & "Billion" & _
                 IIf(tnValue >= 2000000000, "s", "") & NumberToWords(tnValue Mod _
                 1000000000, True)
        End Select

        Return lcNumberToWords
    End Function
But, this doesn't take care of the spacing issue, the casing and the decimals. If someone wants to proceed on enhancing that, you are welcome.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform