Need Help

• Question

• i need help to convert Number into String Like this

if i entered the number 123  then i want the output as  1hundered twenty three:

Thanks For Helping!!!!

Thursday, February 1, 2018 3:46 PM

All replies

• You can use the following function mentioned int he answer

https://social.msdn.microsoft.com/Forums/vstudio/en-US/0b1dec9c-61e9-4544-8134-bda1264a21a4/how-to-convert-number-into-words-in-c?forum=csharpgeneral

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (kokkisajee) or Facebook (sajeetharan)

Thursday, February 1, 2018 3:51 PM
• Type "Convert Numbers to Words C#" on Google : tons of samples...

Thursday, February 1, 2018 3:57 PM
• Hi Manoj1128,

Thank you for posting here.

```static void Main(string[] args)
{
NumberToWords(123);

}

public static string NumberToWords(int number)
{
if (number == 0)
return "zero";

if (number < 0)
return "minus " + NumberToWords(Math.Abs(number));

string words = "";

if ((number / 1000000) > 0)
{
words += NumberToWords(number / 1000000) + " million ";
number %= 1000000;
}

if ((number / 1000) > 0)
{
words += NumberToWords(number / 1000) + " thousand ";
number %= 1000;
}

if ((number / 100) > 0)
{
words += NumberToWords(number / 100) + " hundred ";
number %= 100;
}

if (number > 0)
{
if (words != "")
words += "and ";

var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

if (number < 20)
words += unitsMap[number];
else
{
words += tensMap[number / 10];
if ((number % 10) > 0)
words += "-" + unitsMap[number % 10];
}
}

return words;
}```

Best Regards,

Wendy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Proposed as answer by Wednesday, February 7, 2018 9:03 AM
Friday, February 2, 2018 1:54 AM