This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Convert Number To Character String Representation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert Number To Character String Representation" Watch "Convert Number To Character String Representation" New topic
Author

Convert Number To Character String Representation

chris hayden
Greenhorn

Joined: Mar 13, 2003
Posts: 1
user will enter the number 44 and will be returned forty-four
any suggestions on which classes or methods to use?
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2954
    
  12

If the user enters it, it will already be in String form. Normally to convert an integer (say x) to a String, you can just use:
String s = "" + x;
and to convert a String to an integer:
x = Integer.parseInt(s);
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
He needs to turn:
32 -> thirty-two
75 -> seventy-five
It's not too complicated. You can use the String method toCharArray to convert the string to an array of chars. Then you need to work your way through the array.
A clever way to do it would be to have an array for each unit:
String[] tens = {"ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}
Don't forget that most of the entries in the "ten" group need to be handled differently (thirteen not ten-three).


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert Number To Character String Representation
 
jQuery in Action, 3rd edition