using System;
class Program
{
static void Main()
{
string input;
int number;
bool isValid;
Console.WriteLine("\nEnter 'Blessing' to quit the program at any time\n");
while (true)
{
Console.Write("Enter integer : ");
input = Console.ReadLine();
isValid = int.TryParse(input, out number);
if (!isValid)
Console.WriteLine("\n Not an integer, please try again\n");
else
Console.WriteLine("\n {0}\n", NumberToText(number));
}
}
static string NumberToText(int number)
{
if (number == 0) return "Zero";
int[] num = new int[4];
int first = 0;
int u, h, t;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (number < 0)
{
sb.Append("Minus ");
number = -number;
}
string[] words0 = { "", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine " };
string[] words1 = { "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen " };
string[] words2 = { "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety " };
string[] words3 = { "Thousand ", "Million ", "Billion " };
num[0] = number % 1000;
num[1] = number / 1000;
num[2] = number / 1000000;
num[1] = num[1] - 1000 * num[2];
num[3] = number / 1000000000;
num[2] = num[2] - 1000 * num[3];
for (int i = 3; i > 0; i--)
{
if (num[i] != 0)
{
first = i;
break;
}
}
for (int i = first; i >= 0; i--)
{
if (num[i] == 0) continue;
u = num[i] % 10;
t = num[i] / 10;
h = num[i] / 100;
t = t - 10 * h;
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
return sb.ToString().TrimEnd();
}
}

Pankajkumar PatelRank #181 · 13.4K reputationPosted Nov 16, 2022, 6:46 AM EST
Hi Olusanya Blessing,
Following can be used to Converting Numbers to Words in C# explanation:
class NumberToWords { private static String[] units = { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }; private static String[] tens = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; public static String ConvertAmount(double amount) { try { Int64 amount_int = (Int64)amount; Int64 amount_dec = (Int64)Math.Round((amount - (double)(amount_int)) * 100); if (amount_dec == 0) { return Convert(amount_int) + " Only."; } else { return Convert(amount_int) + " Point " + Convert(amount_dec) + " Only."; } } catch (Exception e) { // TODO: handle exception } return ""; } public static String Convert(Int64 i) { if (i 0) ? " " + Convert(i % 10) : ""); } if (i 0) ? " And " + Convert(i % 100) : ""); } if (i 0) ? " " + Convert(i % 1000) : ""); } if (i 0) ? " " + Convert(i % 100000) : ""); } if (i 0) ? " " + Convert(i % 10000000) : ""); } return Convert(i / 1000000000) + " Arab " + ((i % 1000000000 > 0) ? " " + Convert(i % 1000000000) : ""); } }Use function:
static void Main(string[] args) { try { Console.WriteLine("Enter a Number to convert to words"); string number = Console.ReadLine(); number = ConvertAmount(double.Parse(number)); Console.WriteLine("Number in words is \n{0}", number); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }For more details:
Hope, this will help you!
Aravind GovindarajRank #430 · 5.8K reputationPosted Nov 16, 2022, 5:51 PM EST
Add NPM NumericWordsConversion in you project and pass your value it will yield the desired result
Please find the link for the same
https://www.nuget.org/packages/NumericWordsConversion/