• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert one hundered fifteen thousand into 115000?

 
Greg Kearney
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2591
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Argm Mastoi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg u have to work a bit to create this method, and then u can offer others to utilize it too ;-)
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic