C# Program to convert a given Number into Words

In most of the application it is required to convert the number or amount in words. Following code will help you to convert a given number into words. For example, if “1234″ is given as input, output would be “One Thousand Two Hundred Thirty Four”.

This code will be convert any number between 1 to 9999 in words.

number into words

[csharp]

string[] Ones = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen" };

string[] Tens = { "Ten", "Twenty", "Thirty", "Fourty", "Fift", "Sixty", "Seventy", "Eighty", "Ninty" };

int no = int.Parse(txtNumber.Text);
string strWords = "";

if (no > 999 && no < 10000)
{
int i = no / 1000;
strWords = strWords + Ones[i - 1] + " Thousand ";
no = no % 1000;
}

if (no > 99 && no < 1000)
{
int i = no / 100;
strWords = strWords + Ones[i - 1] + " Hundred ";
no = no % 100;
}

if (no > 19 && no < 100)
{
int i = no / 10;
strWords = strWords + Tens[i - 1] + " ";
no = no % 10;
}

if (no > 0 && no < 20)
{
strWords = strWords + Ones[no - 1];
}

label2.Text = strWords;

[/csharp]


Download Source

About the Author

has written 6 posts.

I work as a freelance consultant and is passionate about taking challenges in all technologies. I am a software consultant and trainer with 8+ years experience in designing, development and maintaining enterprise wide applications. My interests involves Programming, Website development, Learning and Teaching subjects related to Computer Science and Information technology.

Copyright © 2017 TechZoo - Technology Blog. All rights reserved.
Proudly powered by WordPress. Developed by 7Tech Solutions