Win a copy of Spring Boot in Practice this week in the Spring forum!
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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Liutauras Vilda
• Henry Wong
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Al Hobbs
• Carey Brown
Bartenders:
• Piet Souris
• Mikalai Zaikin
• Himai Minh

# How to convert one hundered fifteen thousand into 115000?

Greenhorn
Posts: 7
• Number of slices to send:
Optional 'thank-you' note:
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

Ranch Hand
Posts: 2596
• Number of slices to send:
Optional 'thank-you' note:

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).]

Ranch Hand
Posts: 3244
• Number of slices to send:
Optional 'thank-you' note:
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

Greg Kearney
Greenhorn
Posts: 7
• Number of slices to send:
Optional 'thank-you' note:
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?

Ranch Hand
Posts: 15304
6
• Number of slices to send:
Optional 'thank-you' note:
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

Ranch Hand
Posts: 35
• Number of slices to send:
Optional 'thank-you' note:
Greg u have to work a bit to create this method, and then u can offer others to utilize it too ;-)

Sheriff
Posts: 17031
298
• Number of slices to send:
Optional 'thank-you' note:
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 Lacar
Sheriff
Posts: 17031
298
• Number of slices to send:
Optional 'thank-you' note:
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).]

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.