aspose file tools*
The moose likes Beginning Java and the fly likes How to convert one hundered fifteen thousand into 115000? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert one hundered fifteen thousand into 115000?" Watch "How to convert one hundered fifteen thousand into 115000?" New topic
Author

How to convert one hundered fifteen thousand into 115000?

Greg Kearney
Greenhorn

Joined: Sep 02, 2000
Posts: 7
Are there methods that exist that will help convert word numbers into actual numbers?
Ex:
"one hundred thousand" = 100000
"two hunderd twenty five thousand three hundered fifteen" = 225315
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

Originally posted by Greg Kearney:
Are there methods that exist that will help convert word numbers into actual numbers?
Ex:
"one hundred thousand" = 100000
"two hunderd twenty five thousand three hundered fifteen" = 225315

NO! AFAIK.
You can however do this -
Write a method that would convert each digit of a number to its word (such as one, two, ..., zero) and vice versa. So you can get "one zero zero zero zero zero" for 100000, this should be fairly simple and straightforwrd.
What you say can be done, but you have to take care of many special cases, such as -
11 => eleven, 12 =>twelve (not ten one, ten two)
21 =>twenty one 22 => twenty two ...
Also,
1500 can be fifteen hundred or it can be one thousand and five hundred. I suggest you go for approach no 1 ("One zero zero...").
HTH,
- Manish

[This message has been edited by Manish Hatwalne (edited November 01, 2001).]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Greg
Someone had a similar question the other day and it was suggested that they go look for check writing programs or source code.

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Greg Kearney
Greenhorn

Joined: Sep 02, 2000
Posts: 7
I have missed led you, sorry. I am receiving a string of:
"One hundred fifty five thousand" and I need to return 155000.
Are there any methods that will assist in this effort?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Greg,
I think they answered that question. There are no exisitng methods that will convert any type of string, "One Hundred", or "One", "Two", etc, to a 100, 1, 2 etc.
There may be a third party vendor that has developed one though. Just search the web..

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Argm Mastoi
Ranch Hand

Joined: Oct 16, 2001
Posts: 35
Greg u have to work a bit to create this method, and then u can offer others to utilize it too ;-)
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

Greg,
I suspect this to be a class assignment so all I'll do is give you some hints.
1. Use java.util.StringTokenizer to break down your input string into separate words
2. Use an appropriate class from the Collections framework (see java.util.*) to keep key words and their equivalent types/values
3. Example: one hundred fifty five thousand
inputtype operationresult
onevalue +1
hundredplace marker* 100
fifty value+150
fivevalue+155
thousandplace marker*155000

4. Use polymorphism to do the operations rather than if-then or switch-case statements.
HTH
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
UBB doesn't handle tables very well

[This message has been edited by JUNILU LACAR (edited November 03, 2001).]


Junilu - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

Just realized something too:
There are other things that you need to check besides those implied in my previous post. Take for example the input string of "two hundred twenty five thousand three hundred fifteen". If you don't consider other factors, you might end up with 22500315 instead of 225315.
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by JUNILU LACAR (edited November 03, 2001).]
 
wood burning stoves
 
subject: How to convert one hundered fifteen thousand into 115000?