This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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).]
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..
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
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).]
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).]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How to convert one hundered fifteen thousand into 115000?