Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Serial Number in SSRS Articles
Get Started Developing for Android Apps with Eclipse Articles
How to Print a Crystal Report direct to printer Articles
Razor View Engine Interview Questions Answers Interview Questions
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
SPIRE PDF Library Articles
Infosys Interview Questions Interview Questions
Html5 interview questions and answers Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
SharePoint 2010 interview Questions Answers Interview Questions
Submit Articles | More Articles..

How To convert a Number into Word

Posted By: piyushkumarg7@gmail.com On:7/14/2010 12:50:25 AM in:Source Codes Category:VB.NET Hits:4394
Following code will be helpfull to convert a number  into word 

' Convert a number between 0 and 999 into words.

Public Function NumToWords(ByVal num As Integer) As _

    String

    Static one_to_nineteen() As String = {"Zero", "One", _

        "Two", "Three", "Four", "Five", "Six", "Seven", _

        "Eight", "Nine", "Ten", "Eleven", "Twelve", _

        "Thirteen", "Fourteen", "Fifteen", "Sixteen", _

        "Seventeen", "Eightteen", "Nineteen"}

    Static multiples_of_ten() As String = {"Twenty", _

        "Thirty", "Forty", "Fifty", "Sixty", "Seventy", _

        "Eighty", "Ninety"}

 

    ' If the number is 0, return an empty string.

 

    If num = 0 Then Return ""

 

    ' Handle the hundreds digit.

    Dim digit As Integer

    Dim result As String = ""

 

    If num > 99 Then

        digit = num \ 100

        num = num Mod 100

        result = one_to_nineteen(digit) & " hundred"

    End If

 

    ' If num = 0, we have hundreds only.

 

    If num = 0 Then Return result.Trim()

 

    ' See if the rest is less than 20.

 

    If num < 20 Then

        ' Look up the correct name.

 

        result &= " " & one_to_nineteen(num)

    Else

        ' Handle the tens digit.

 

        digit = num \ 10

        num = num Mod 10

        result &= " " & multiples_of_ten(digit - 2)

 

        ' Handle the final digit.

 

        If num > 0 Then

            result &= " " & one_to_nineteen(num)

        End If

    End If

 

    Return result.Trim()

End Function

comments powered by Disqus
User Profile
Piyush Kumar
.Net Programmer
New Delhi , India
Email :You must Log In to access the contact details.
Latest Post from :piyushkumarg7@gmail.com
Normalization
View: 1864 | Submitted on: 7/28/2010 11:37:14 PM
What is MVC?
View: 1897 | Submitted on: 7/26/2010 5:02:22 AM
Deleting Duplicate rows from a table
View: 2309 | Submitted on: 7/14/2010 1:50:14 AM
How To convert a Number into Word
View: 4394 | Submitted on: 7/14/2010 12:50:25 AM
Serial Number in SSRS
View: 18672 | Submitted on: 7/12/2010 6:25:55 AM
Submit Articles | All Post of This User..


Advertise About Us Private Policy Terms of use
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher