This is a part of program for converting number to text in indonesian language.
I use this program to complete my final project.
I hope this post help anyone who want to create program like this.
Thanks.
Here is the code:
private static String[] theNumber = {"nol",
"satu",
"dua",
"tiga",
"empat",
"lima",
"enam",
"tujuh",
"delapan",
"sembilan",
"sepuluh",
"sebelas"
};
private String num2Text(int number) {
if (number/1000 > 0)
return cek4se(number/1000) + "ribu " + residu(number%1000);
else if (number/100 > 0)
return cek4se(number/100) + "ratus " + residu(number%100);
else if (number/10 > 0 && number>11){
if (number>19)
return num2Text(number/10) + "puluh " + residu(number%10);
else
return num2Text(number%10) + "belas ";
}
else
return theNumber[number] + " ";
}
private String cek4se(int number) {
if (number == 1)
return "se";
else return num2Text(number);
}
private String residu(int number) {
if (number > 0)
return num2Text(number);
else return "";
}