Hello Sir, I have used bellow code for convert number to word. It is working nice. But when i enter input type numberDecimal in android EditText, Unfortunately stop my app. Please help me to convert numberDecimal to word.... final private static String[] units = {"Zero","One","Two","Three","Four", "Five","Six","Seven","Eight","Nine","Ten", "Eleven","Twelve","Thirteen","Fourteen","Fifteen", "Sixteen","Seventeen","Eighteen","Nineteen"}; final private static String[] tens = {"","","Twenty","Thirty","Forty","Fifty", "Sixty","Seventy","Eighty","Ninety"}; public static String convertToWord(Integer i) { // if( i < 20) return units; if( i < 100) return tens[i/10] + ((i % 10 > 0)? " " + convertToWord(i % 10):""); if( i < 1000) return units[i/100] + " Hundred" + ((i % 100 > 0)?" and " + convertToWord(i % 100):""); if( i < 1000000) return convertToWord(i / 1000) + " Thousand " + ((i % 1000 > 0)? " " + convertToWord(i % 1000):"") ; return convertToWord(i / 1000000) + " Million " + ((i % 1000000 > 0)? " " + convertToWord(i % 1000000):"") ; }
Welcome to Android Forums. This thread was moved to this forum that is dedicated to development subjects. ... Thom
Working with the code you have, I would say the steps to do this are:- 1. Separate the decimal number into whole part, and fractional part 2. The whole part can be handled by your current code 3. For the fraction, iterate over each single digit, calling convertToWord() each time This should build up the complete number.