Convert Number to words

Posted by Vivekjj under ASP.NET on 11/9/2012 | Points: 10 | Views : 3355 | Status : [Member] | Replies : 5
Hi i have created crystal report and calculated sum of one column, the sum is 2500 .. I need to convert this 2500 to words like "Two Thousand Five Hundred Only ". Tel me the code if any?

Responses

Posted by: Krishnamanohar on: 11/9/2012 [Member] Starter | Points: 25
 0 Hi Vivek Try This Pass Your Value Instead of Number 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; }Vivekjj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Hariinakoti on: 11/9/2012 [Member] Starter | Points: 25