Hi friends, I am going to write a C# program to Convert Number to Word.
C# Program to Convert Number to Word:
In most of the application, it is required to convert the number or amount of words. Following code will help you to convert a given number into words. For example, if “1235″ is given as input, the output would be “One Thousand Two Hundred Thirty-Five”.
Here is the source code.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { 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" }; Console.WriteLine("Enter a Number"); int iNumber = int.Parse(Console.ReadLine()); string sWords = ""; if (iNumber > 999 && iNumber < 10000) { int i = iNumber / 1000; sWords = sWords + Ones[i - 1] + " Thousand "; iNumber = iNumber % 1000; } if (iNumber > 99 && iNumber < 1000) { int i = iNumber / 100; sWords = sWords + Ones[i - 1] + " Hundred "; iNumber = iNumber % 100; } if (iNumber > 19 && iNumber < 100) { int i = iNumber / 10; sWords = sWords + Tens[i - 1] + " "; iNumber = iNumber % 10; } if (iNumber > 0 && iNumber < 20) { sWords = sWords + Ones[iNumber - 1]; } Console.WriteLine(sWords); Console.ReadKey(); } }
Output:
Enter a Number 344 Three Hundred Fourty Four
View More:
- C# Program to find all substrings from a String.
- C# Program to read text File line by line.
- C# Program to Sort a String Array in Ascending Order.
- Static vs Non Static Keyword in C#.
Conclusion:
I hope you would love this post. Your feedback and suggestions would be appreciated. Please don’t hesitate to comment for any technical help.
Thank You.