Conversion Of Big Number into Words(In Indian System).
package snlkjha;
import java.util.*;
import java.math.BigInteger;
/**
* @author snlkjha
*/
public class N2word {
public static String get(int n){
String[] x1={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thrteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Ninteen"};
String[] x2={"","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninty","Hundred"};
if(n<20) return x1[n];
else return x2[n/10]+" "+x1[n%10];
}
public static String convert_number_into_words(BigInteger n){
String message=" Only",x3[]={"","Hundred","Thousand","Lakh","Crore","Arab","Kharab","Nil","Padma","Shankh","Mahashankh"};
int k=0,divide[]={100,10,100,100,100,100,100,100,100,100,100};
int remainder[]={10,100,100,100,100,100,100,100,100,100,100};
int rem =n.remainder(BigInteger.valueOf(100)).intValue(); /*Decimal*/
message=get(rem)+message;
while(n.compareTo(BigInteger.valueOf(0))>0){
n=n.divide(BigInteger.valueOf(divide[k])); /*till MahaShankh*/
rem=n.remainder(BigInteger.valueOf(remainder[k++])).intValue();
if(rem>0)
message=get(rem)+" "+x3[k]+" "+message;
}
return message;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.print("Enter the Amount(Max 21 digits): ");
BigInteger num=scan.nextBigInteger();
if(num.compareTo(BigInteger.valueOf(1))<0||num.toString().length()>21){
System.out.println("Out of range.");
System.exit(0);
}
System.out.println("Amount : "+num+".00"+"\nIn Words :"+convert_number_into_words(num));
}
}
Output:
Enter the Amount: 459632587412369
Amount : 459632587412369.00
In Words :Forty Five Nil Ninty Six Kharab Thirty Two Arab Fifty Eight Crore Seventy Four Lakh Twelve Thousand Three Hundred Sixty Nine Only