Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Writing numbers

 
Ranch Hand
Posts: 182
  • 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
 
Ranch Hand
Posts: 618
  • 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.
 
Ranch Hand
Posts: 86
  • 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
  • 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 ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic