wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing numbers" Watch "Writing numbers" New topic
Author

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.
Thanks,
Francisco


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I doubt it...you'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: http://aspose.com/file-tools
 
subject: Writing numbers
 
Similar Threads
DOM to string
CONVERTING an application to an applet
Convert DefaultStyledDocument to HTMLDocument
Converting Document to String
string to float conversion round off problem