View Single Post
  #2 (permalink)  
Old September 30th, 2003, 12:54 PM
nikolai nikolai is offline
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you'd write a program that does pretty much what you do as a person.

You should go right-to-left, since you don't know what place-value any digits on the left have until you count how many places they are from the right.

You'd check the right-most two digits first, since "22" is parsed differently from "12", etc. All other number words are of a specific format, namely "<number> <value>", e.g. "three thousand".

The way I'd handle it is to write a function that converts at most a three-digit number. From "zero" to "nine hundred ninety nine".

The reason being is that for all other place values, you'll only need to generate this name and append a place value modifier.

For example: 1,234,567,890 is broken up into four three-digit parts: 001 234 567 890.

Your application simply needs to convert each three digit part to text and append an additional modifier. Your final answer will be the concatenation of all these strings.

 threeDigitToText(001) + " billion " +
 threeDigitToText(234) + " million " +
 threeDigitToText(567) + " thousand " +
 threeDigitToText(890)


Since this sounds suspiciously like a homework assignment, I'm not going to write any the code, but this should be enough to get you started.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote