Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

converting numbers into words using double

  Asked By: Everett    Date: Sep 23    Category: Java    Views: 2631
  

We had a case
study which has a problem of converting numbers into words using
double, but in which we must not use loopings. for example:

9257 ---------> nine thousand two hundred fifty-seven

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Salvador Alexander     Answered On: Sep 23

Here is another way to do it.(recursive way(shorter) or you can do it without
recursive(long))

this is a recursive method

static i = 0;
public static void convert(int num)
{
if (num < 10)
{ switch num
{
case 1: System.out.print("one"); break;
case 2: .......................
........................case 9 :
}
switch i
{ case 1: System.out.print("tens"); break;
case 2: System.out.print("hundreds"); break;
................
}
else
{ i++
convert(num / 10);
switch (num%10) {
case 1: System.out.print("one"); break;
case 2: .......................
........................case 9 :
}
}
}
you can keep track of the position of the number to determine (thousand,
hundred....)

you can use double  as parameter but you should treat it in slightly different
way
I hope you will help you.

 
Didn't find what you were looking for? Find more on converting numbers into words using double Or get search suggestion and latest updates.




Tagged: