File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes Numeric value convert to word  format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Numeric value convert to word  format" Watch "Numeric value convert to word  format" New topic

Numeric value convert to word format

Mahendra Darwatkar

Joined: Apr 07, 2000
Posts: 20
Hi !!
Can anybody guide me how can i convert value 125 to word format "One Hundred Twenty Five"

Awaiting reply...
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The best place to discuss this question may be the "Cattle Drive" forum, so I've moved this message...

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
Without giving you each and every step. I would say that you've to do the following:
split the number and place into an array.
125 -
5 to be the first element of the array - hence the ones place
2 to be the second element of the array - hence the tenth place
1 to be the third element of the array - hence the hundredth place.
then you evaluate each element in the array.
if the first element is 5 then textToPrint='five'
if the second elemnet is 2 then textToPrint ='twenty'+textToPrint
if the third element is 1 then textToPrint='one hundred'+textToPrint
------------------the end
To handle any given number, you'd have to use loops, arrays for the 'text', formatting, handle special cases (ie. 0's).
This should be enough to get you going.

Zeba Mojez

Joined: Oct 25, 2000
Posts: 10
here is the coding for your question

I added ubb code tags to preserve the indenting.


[This message has been edited by Marilyn deQueiroz (edited November 26, 2000).]
paul wheaton

Joined: Dec 14, 1998
Posts: 20972

I think there is a better solution.
A switch statement will do a compare with every constant. So you're looking at a whole lot of compares.
What you need is a data structure that will find your information by just doing a little math. It would be really nice if Java would abstract that math away from you.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Mahendra Darwatkar

Joined: Apr 07, 2000
Posts: 20
Dear Shama Khan, Zeba Mojez, Paul Wheaton
Thanks for your feedback to my difficulty... Still I am not that much clear how to convert values to word format...
Can anybody send me small whole class to do this things...
Awaiting for your feedback pl..


I agree. Here's the link:
subject: Numeric value convert to word format
It's not a secret anymore!