!**********************************************************************
!* 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
!**********************************************************************
|