Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

NumberToWords - Convert a number into its string representation
[ All Languages » VB »  String]

Total Hit ( 1853)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Convert a number into its textual equivalent.
'
' Pass True in the second argument if you want a null string when
' zero is passed.
' This is a recursive routine that is probably the most concise
' routines that solves the problem

Function NumberToWords(ByVal Number As Long, Optional BlankIfZero As Boolean) _
  As String
  Select Case Number
    Case 0
      NumberToWords = IIf(BlankIfZero, "", "Zero")
    Case 1 To 19
      NumberToWords = Choose(Number, "One", "Two", "Three", "Four", _
        "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", _
        "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
        "Seventeen", "Eighteen", "Nineteen")
    Case 20 To 99
      NumberToWords = Choose(Number \ 10 - 1, "Twenty", "Thirty", _
        "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", _
        "Ninety") & NumberToWords(Number Mod 10, True)
    Case 100 To 999
      NumberToWords = NumberToWords(Number \ 100) & "Hundred" & IIf _
        (Number >= 200, "s", "") & NumberToWords(Number Mod 100, True)
    Case 1000 To 999999
      NumberToWords = NumberToWords(Number \ 1000) & "Thousand" & IIf _
        (Number >= 2000, "s", "") & NumberToWords(Number Mod 1000, True)
    Case 1000000 To 999999999
      NumberToWords = NumberToWords(Number \ 1000000) & "Million" & IIf _
        (Number >= 2000000, "s", "") & NumberToWords(Number Mod 1000000, _
        True)
    Case Is >= 1000000000
      NumberToWords = NumberToWords(Number \ 1000000000) & "Billion" & _
        IIf(Number >= 2000000000, "s", "") & NumberToWords(Number Mod _
        1000000000, True)
  End Select
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.