NL-Func - Numeric Value to Literal String Translation
 Yesterday someone signed my Guest Book and mentioned they were looking for a routine to convert a number into a literal string. This sounded like an interesting little algorithm to develop. This 'literal' translation is typically required when printing checks. This is also a good opportunity to post more pictures! Here's some more ZOO animals... on the left giraffes and a couple of rhinos at the bottom!

You can find the NL-Func function in my custom SQR library TDFUNC.SQC

Thanks to Terry for the idea to develop the NL-Func routine!

You can view (or even sign) my Guestbook by clicking <HERE>!

NOTE:
PeopleSoft users may be familiar with the delivered NETINWDS.SQC which
provides similar functionality (You must include the LDNUMLIT.SQC as well).
These routines are used in their check generation programs. The PeopleSoft
routine wastes array space and is a bit primitive. It may also leave extra spaces
between words in some cases (for large amounts each space is precious). I must
admit I like my routine better!

 NL-Func Parameters - Convert Number to Text Literal

 Input    - Numeric Value (0 to 999,999,999,999.99)
 Output  - Literal Text String

 NL-Func - Some Sample Translations
 NUMERIC VALUE LITERAL STRING TRANSLATION 123.45 One Hundred Twenty-Three and 45/100 900035000.00 Nine Hundred Million Thirty-Five Thousand 888000.88 Eight Hundred Eighty-Eight Thousand and 88/100 11003.25 Eleven Thousand Three and 25/100 .50 Zero and 50/100 999999999999.99 Nine Hundred Ninety-Nine Billion Nine Hundred Ninety-Nine Million Nine Hundred Ninety-Nine Thousand Nine Hundred Ninety-Nine and 99/100 Hmmm... this example seems a bit ridiculous! NOTE: The Peoplesoft Delivered routine blew up with this example! So if you need to print checks in the billions you may wish to use my NL-Func!

 NL-Func - Source Code
 ```!********************************************************************** !* Numeric to Literal String Translation * !********************************************************************** !* * !* INPUT: #I_num - Number (0 to 999,999,999,999.99) * !* OUTPUT: \$O_lit - Literal Interpretation * !* * !* To de-activate this function: * !* #define NL_Func_Remove * !* * !********************************************************************** !* * !* EXAMPLE: do NL-Func(123.45, \$O_lit) * !* * !* RESULTS: \$O_lit = 'One Hundred Twenty-Three and 45/100' * !* * !********************************************************************** #ifndef NL_Func_Remove begin-procedure NL-Array create-array name=NLmtx size=28 field=NLtxt:char ! Direct Indexing Literals let NLmtx.NLtxt (1) = 'One' let NLmtx.NLtxt (2) = 'Two' let NLmtx.NLtxt (3) = 'Three' let NLmtx.NLtxt (4) = 'Four' let NLmtx.NLtxt (5) = 'Five' let NLmtx.NLtxt (6) = 'Six' let NLmtx.NLtxt (7) = 'Seven' let NLmtx.NLtxt (8) = 'Eight' let NLmtx.NLtxt (9) = 'Nine' let NLmtx.NLtxt (10) = 'Ten' let NLmtx.NLtxt (11) = 'Eleven' let NLmtx.NLtxt (12) = 'Twelve' let NLmtx.NLtxt (13) = 'Thirteen' let NLmtx.NLtxt (14) = 'Fourteen' let NLmtx.NLtxt (15) = 'Fifteen' let NLmtx.NLtxt (16) = 'Sixteen' let NLmtx.NLtxt (17) = 'Seventeen' let NLmtx.NLtxt (18) = 'Eighteen' let NLmtx.NLtxt (19) = 'Nineteen' let NLmtx.NLtxt (20) = 'Twenty' ! Combination Indexing Literals let NLmtx.NLtxt (21) = 'Thirty' let NLmtx.NLtxt (22) = 'Forty' let NLmtx.NLtxt (23) = 'Fifty' let NLmtx.NLtxt (24) = 'Sixty' let NLmtx.NLtxt (25) = 'Seventy' let NLmtx.NLtxt (26) = 'Eighty' let NLmtx.NLtxt (27) = 'Ninety' let #NLmax = 27 let \$NLsw = 'Y' end-procedure !********************************************************************** !* Numeric to Literal String Translation (Process) * !********************************************************************** begin-procedure NL-Func(#I_num, :\$O_lit) if \$_NLsw <> 'Y' do NL-Array end-if let \$O_lit = '' let #I_num = abs(#I_num) let \$num = edit(#I_num, '099999999999.99') ! Set Level Parameters (Element String, Length, Occurs) ! ' Billion Million Thousand Hundred Cents ' ! '11111111112222222222333333333344444444445555555555' let \$L_str = ' Billion \$ Million \$ Thousand \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$' let #L_pos = 1 let #L_len = 10 let #L_occ = 5 let #pos = 1 let #lev = 1 let \$lit = '' while #lev <= (#L_occ - 1) let \$seg = substr(\$num, #pos, 3) if \$seg > '000' let \$str = rtrim(substr(\$L_str, #L_pos, #L_len),'\$') let \$hi = substr(\$seg, 1, 1) let \$lo = substr(\$seg, 2, 2) let #hi = to_number(\$hi) let #lo = to_number(\$lo) if #hi > 0 let \$lit = \$lit || NLmtx.NLtxt (#hi) || ' Hundred' if #lo > 0 let \$lit = \$lit || ' ' end-if end-if ! Combination Indexing if #lo > 20 let #adj = trunc(#lo/10,0) + 18 let \$lit = \$lit || NLmtx.NLtxt (#adj) let #lo = mod(#lo,10) if #lo > 0 let \$lit = \$lit || '-' end-if end-if ! Direct Indexing if #lo > 0 let \$lit = \$lit || NLmtx.NLtxt (#lo) end-if let \$lit = \$lit || \$str end-if let #lev = #lev + 1 let #pos = #pos + 3 let #L_pos = #L_pos + #L_len end-while if \$lit = '' let \$lit = 'Zero' end-if ! Now process the cents portion let \$dec = substr(\$num, #pos+1, 2) if \$dec <> '00' let \$lit = \$lit || ' and ' || \$dec || '/100' end-if let \$O_lit = \$lit end-procedure #endif !********************************************************************** ```

 Feedback
 I would appreciate any feedback you may have on this site. Send mail to tdelia@erols.com or click on the Octopus.

 Technical difficulties?
 Please report any technical difficulties you may encounter to the address above OR click on the Octopus. Thanks.