File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing numbers

 
Francisco A Guimaraes
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephen Huey
Ranch Hand
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sam Moran
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic