|
This is a VERY common problem given in school while learning programming. Basically, you build 3 arrays. "One" "Two" "Three" "Four" "Five" "Six" "Seven" "Eight" "Nine" "Ten" "Eleven" "Twelve" "Thirteen" "Fourteen" "Fifteen" "Sixteen" "Seventeen" "Eighteen" "Nineteen" "*BLANK" "Twenty" "Thirty" "Forty" "Fifty" "Sixty" "Seventy" "Eighty" "Ninety" "Hundred" "Thousand" "Million" And it's a lot of comparing. Take any given number, 12,345.67. You start at the left, which is the 10 thousands place. Take the next digit also, so you have "12". It's under 20, so is one of the first 19 numbers, it's the 12th one in fact, which is "Twelve". It is in the thousands place, so you add "thousand". Take the next digit over, the hundreds place. Take it alone, it is "3" so you add "Three" and "Hundred". Take the next 2 characters, the 10's and 1's place. It's over 20, so you need to add 2 words. the first is "4" so it is the 4th in our 10's characters, or "Forty". Take the last digit, 5 and add "Five" Add the word "And" Then take the cents, 67, is over 20, so take the 6th 10's place string, "Sixty" and add the 1's column, "Seven". And "cents" to the end. "Twelve thousand Three Hundred Forty Five And Sixty Seven cents" And you have to look for any special cases too. Remember to ignore 0's in some cases but not all. Ignore 0's after 100 (say "One Hundred") but not in 10 (say "Ten" not "One"). Have fun. Regards, Jim Langston boothm@earth.goddard.edu wrote: > Nah, don't let him off that easy. He has to say the thousands, hundreds, > and tens&teens, too > > Please respond to RPG400-L@midrange.com > Sent by: owner-rpg400-l@midrange.com > To: <RPG400-L@midrange.com> > cc: > > Subject: RE: converting numeric into words > > Just say "One Five Zero and two five cents". All you do is load your > amount > into an array and check each element replacing the number with a word by > using the number as an index to another array (or a SELECT group if you > prefer). > > +--- > | This is the RPG/400 Mailing List! > | To submit a new message, send your mail to RPG400-L@midrange.com. > | To subscribe to this list send email to RPG400-L-SUB@midrange.com. > | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. > | Questions should be directed to the list owner/operator: david@midrange.com > +--- +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.