This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Writing numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing numbers" Watch "Writing numbers" New topic

Writing numbers

Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
Hi, everybody. I have the following problem: I need to convert a number into text, e.g., if I get '1' I want to convert it to 'One'. Anyone knows if there is a java program that does it? Any help is deeply appreciated.

Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="" target="_blank" rel="nofollow">here</a> to see an example.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I doubt'll just need a table to pull from to map the numerical numbers with the word versions.
For instance, if the number is between 100 and 1000, you know you'll need to get the first digit (e.g. output "one" for 1, "six" for 6, etc), then "hundred", then do the same with the tens and ones digits.
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
Here is something that I started for you, if you add to it I would appreciate any additional work. I am sure that there are better ways to do this but this is quick:

[ November 21, 2003: Message edited by: Sam Moran ]
[ November 21, 2003: Message edited by: Sam Moran ]

We make a living by what we get, we make a life by what we give!
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
I spent a little more time and did some cleaning and pruning. I have declared the 2 arrays as global and assign the values in the Main. Now I have two simple functions that work up to 99,999:

[ November 24, 2003: Message edited by: Sam Moran ]
I agree. Here's the link:
subject: Writing numbers
It's not a secret anymore!