You write a procedure that looks at each digit and chooses the words that describe the digit in that position. Usually you will have a few arrays that will hold the various words such as "nine hundred", "ninety" and "nine".
So from your example value 999, your program would find that the first significant digit was the 9 in the hundreds position. It could then retrieve the ninth value from the array for hundreds. That value might be "nine hundred". Your program moves that string to the output string.
The program then moves to the next position -- the tens. It finds a 9, so it retrieves the ninth entry from the array for tens -- "ninety". It concatenates that to the value already in the output string to get a new value -- "nine hundred ninety".
Overall, your program simply goes through the digits and selects the appropriate strings for all of the parts. The strings get concatenated together.
You can work left-to-right and build the output string as you go along. Or you can go through the digits (in either direction) and build a list of words that you concatenate together after processing all of the digits. Or you can go through the digits (in either direction) and simply set all the array indexes -- string the array elements together after finishing the digits. Or...
Well, there are lots of possible ways, probably as many ways as there are people who might read this item. The "right" way depends on how perfect the result must be according to some specified requirement, how efficient it needs to be, how important the precise details such as hyphenation are, whether decimal positions are involved... whether you're coding in RPG II or Smalltalk or other language...
This is "introductory"-level concepts stuff. Are you learning programming? Lots of examples of coding are out on the internet.
Last Wiki Answer Submitted: March 17, 2010 10:56 pm by TomLiotta108,055 pts.
All Answer Wiki Contributors: TomLiotta108,055 pts.