aspose file tools*
The moose likes Beginning Java and the fly likes string display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string display" Watch "string display" New topic
Author

string display

preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111
how to display an integer like 22 in the format twenty-two?
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Preeti,
Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,

int deci = 22 / 10; // equals 2 because it's integer division
and then
int uni = 22 % 10; // equals 2 because that's the remainder
Now set up two arrays like this,

and get the String representation as such,
String result = deciStrings[deci] + "-" + uniStrings[uni+1];
Of course, you have to derive the logic to make this handle any number. Hope this helps.
Sean
preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111
thanks Sean for putting me on the right track
preeti
Harish Babu.N
Greenhorn

Joined: Oct 12, 2000
Posts: 11
Hi
Bug in u'r code
Use
String result = deciStrings[deci-1] + "-" + uniStrings[uni];


Originally posted by Sean MacLean:
[B]Preeti,
Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,

int deci = 22 / 10; // equals 2 because it's integer division
and then
int uni = 22 % 10; // equals 2 because that's the remainder
Now set up two arrays like this,

and get the String representation as such,
String result = deciStrings[deci] + "-" + uniStrings[uni+1];
Of course, you have to derive the logic to make this handle any number. Hope this helps.
Sean[/B]

 
 
subject: string display