# string display

preeti dengri
Ranch Hand
Posts: 111
how to display an integer like 22 in the format twenty-two?

Sean MacLean
author
Ranch Hand
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
Posts: 111
thanks Sean for putting me on the right track
preeti

Harish Babu.N
Greenhorn
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]