• # Convert amount to words

how to convert the amount(numbers) to words(indian rupees)... thank you in advance
• Hi,
You may find many article in this regard. Please refer below couple of good articles where you will find sample code and detailed explanation:
softwareandfinance.com/CSharp/Number_To_Text.html

Regards,
Asheej T K

• Hi,
http://www.codeproject.com/Articles/106122/Convert-Numeric-Currency-into-Words-For-INDIAN-Cur
http://forums.asp.net/t/1634022.aspx?Translation+of+Indian+currency+to+words

• You need to first get the digit from digit from amount and then use the switch case to identify the numbers and finally concatenate them to get full words
see below code snippet for more detail
http://www.codeproject.com/Articles/15934/How-to-Convert-a-Numeric-Value-or-Currency-to-Engl

Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]

• Please refer the below sample code for converting numbers to word

`public static string ConvertNumberToWords(int number){ if (number == 0) return "zero"; if (number < 0) return "minus " + NumberToWords(Math.Abs(number)); string strstrWords = ""; if ((number / 1000000) > 0) { strWords += NumberToWords(number / 1000000) + " million "; number %= 1000000; } if ((number / 1000) > 0) { strWords += NumberToWords(number / 1000) + " thousand "; number %= 1000; } if ((number / 100) > 0) { strWords += NumberToWords(number / 100) + " hundred "; number %= 100; } if (number > 0) { if (strWords != "") strWords += "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) strWords += unitsMap[number]; else { strWords += tensMap[number / 10]; if ((number % 10) > 0) strWords += "-" + unitsMap[number % 10]; } } return strWords;}`

Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM

• using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConvertNumToText
{
class Program
{

string str;

string[] a=new string[]{"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", };

string[] b = new string[] { "hundred", "thousand", "lakh", "crore", "million" };

string[] c=new string[]{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", };

String[] d=new string[]{ "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" };

public string convertNumToWord(long number)
{

int c=1;
long rm ;
str="";
while ( number != 0 )
{
switch ( c )
{
case 1 :
rm = number % 100 ;
pass ( rm ) ;
if( number > 100 && number % 100 != 0 )
{
display ( "and " ) ;
}
number /= 100 ;

break ;

case 2 :
rm = number % 10 ;
if ( rm != 0 )
{
display ( " " ) ;
display ( b[0] ) ;
display ( " " ) ;
pass ( rm ) ;
}
number /= 10 ;
break ;

case 3 :
rm = number % 100 ;
if ( rm != 0 )
{
display ( " " ) ;
display ( b[1] ) ;
display ( " " ) ;
pass ( rm ) ;
}
number /= 100 ;
break ;

case 4 :
rm = number % 100 ;
if ( rm != 0 )
{
display ( " " ) ;
display ( b[2] ) ;
display ( " " ) ;
pass ( rm ) ;
}
number /= 100 ;
break ;

case 5 :
rm = number % 100 ;
if ( rm != 0 )
{
display ( " " ) ;
display ( b[3] ) ;
display ( " " ) ;
pass ( rm ) ;
}
number /= 100 ;
break ;

case 6:
rm = number % 100;
if (rm != 0)
{
display(" ");
display(b[4]);
display(" ");
pass(rm);
}
number /= 100;
break;

}
c++ ;
}

return str;
}

public void pass(long number)
{
long rm, q ;
if ( number < 10 )
{
display ( a[number] ) ;
}

if ( number > 9 && number < 20 )
{
display ( c[number-10] ) ;
}

if ( number > 19 )
{
rm = number % 10 ;
if ( rm == 0 )
{
q = number / 10 ;
display ( d[q-2] ) ;
}
else
{
q = number / 10 ;
display ( a[rm] ) ;
display ( " " ) ;
display ( d[q-2] ) ;
}
}
}

public void display(string s)
{
string t ;
t= str ;
str= s ;
str+= t ;
}

public string displayInText(long number)
{
Program num = new Program();
//System.out.println("num.convertNumToWord(0)"+num.convertNumToWord(100));
string numberInText = num.convertNumToWord(number);
return numberInText;
}

static void Main(string[] args)
{
Console.WriteLine("enter the amount in number");
//Scanner sc=new Scanner(System.in);
Program t = new Program();
string[] a=number.Split('.');
Console.Write(t.displayInText(Convert.ToInt64(a[0])));
Console.Write(" rupees");
if (a.Length > 1)
{
Console.Write(" and ");
Console.Write(t.displayInText(Convert.ToInt32(a[1])));
Console.Write(" paise");
}
Console.Write(" only");
}

}
}

• Hi..

Go through the below mentioned links.. This may help u..