cancel
Showing results for 
Search instead for 
Did you mean: 

Converstion of Numbers to Words

ParthibanAyyap2
Level 3
Hi All, I need to create this Object for converting amount in words. Which can manipulate with decimal setting, Doller (any currency) Prefix. Does any one has the code or object.
2 REPLIES 2

TomBlackburn1
Level 7
Hi Parthiban759, If i've understood correctly you want to correctly the solution below should work (I'm C#, so its not VB as per other solution above): ======================== GLOBAL CODE ======================== 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; } =============== CODE STAGE =============== myOutputText = NumberToWords(121591561); Or whatever number you want Thanks Tom

Thanks for the Reply Tom, It was helpful. I made few changes in the code.