Re: Displaying money values as words (check writing)
Posted in 1996
mhodges (mhodges@bessel.nando.net) wrote: : I need to write out money variables to a report as words instead of : numbers to print checks (i.e. ONE THOUSAND TWO HUNDRED THIRTY AND NO CENTS). 4GL? I put some 4GL code in our TechInfo database (may be accessible via I-Link but I'm not sure) that does that. I didn't write it myself, and I don't remember whether I even tested it before I put it there, so if you have any problems with it, you didn't get it from me ;-) I've attached it below, in case you don't have access to I-Link or it's not there. BTW, I-Link does contain a lot of useful (and useless) stuff like this. (Oh boy, I'm starting to sound like Clem, plugging our other services ;-) June ---- June Tong Informix Software ---- ---- Senior Consultant (415) 926-6140 ---- ---- International Support junet@informix.com ---- ---- Location-du-jour: Miami ---- * * Standard disclaimers apply * - Please do not send me requests/questions by mail. When I have the knowledge - and time permits, I try to answer questions on comp.databases.informix, but - travel schedule, time, and volume make responding to personal requests - difficult and often slow. Please call your local Informix Technical Support - organization for assistance with technical issues. ---------------------------- TI #4160 ---------------------------- Title: Print English Text for American Money Values (for checks) Sub. Date: 04/15/1993 This 4GL program produces the American-English representation of a money value (in American Dollars). Short Desc: Would like to have character representation of money for checks Long Desc: It would be nice to have a function to print the character string of a money field, as is done on checks. $250.00 would be printed Two Hundred and Fifty Dollars and No Cents. ---------------------------- Cut Here ---------------------------- globals define tens array[10] of varchar(20) define ones array[20] of varchar(20) define units array[22] of varchar(20) end globals main call init_names() call number(0) call number(12) call number(1234) call number(1234.78) call number(1234567890.12) call number(1000) call number(2000000) call number(3000000000.0) call number(40000000000000.0) call number(5000000000000000.0) call number(6000000000000000000.0) call number(7000000000000000000000.0) call number(8000000000000000000000000.0) call number(1.23456789e27) call number(1.23456789e28) call number(1.23456789e29) end main function number(m) define m money(32,2), result varchar(255) call mtoa(m, 0) returning result display m, " = ", result end function function init_names() let ones[1] = "One" let ones[2] = "Two" let ones[3] = "Three" let ones[4] = "Four" let ones[5] = "Five" let ones[6] = "Six" let ones[7] = "Seven" let ones[8] = "Eight" let ones[9] = "Nine" let ones[10] = "Ten" let ones[11] = "Eleven" let ones[12] = "Twelve" let ones[13] = "Thirteen" let ones[14] = "Fourteen" let ones[15] = "Fifteen" let ones[16] = "Sixteen" let ones[17] = "Seventeen" let ones[18] = "Eighteen" let ones[19] = "Nineteen" let tens[1] = "Ten" let tens[2] = "Twenty" let tens[3] = "Thirty" let tens[4] = "Forty" let tens[5] = "Fifty" let tens[6] = "Sixty" let tens[7] = "Seventy" let tens[8] = "Eighty" let tens[9] = "Ninety" let units[1] = "Thousand" let units[2] = "Million" let units[3] = "Billion" let units[4] = "Trillion" let units[5] = "Quadrillion" let units[6] = "Quintillion" let units[7] = "Sextillion" let units[8] = "Septillion" let units[9] = "Octillion" let units[10] = "Nonillion" let units[11] = "Decillion" let units[12] = "Undecillion" let units[13] = "Duodecillion" let units[14] = "Tredecillion" let units[15] = "Quattuordecillion" let units[16] = "Quindecillion" let units[17] = "Sexdecillion" let units[18] = "Septendecillion" let units[19] = "Octodecillion" let units[20] = "Novemdecillion" let units[21] = "Vigintillion" end function function mtoa(m, level) define m decimal(32,2), old decimal(32,2), level int, x, y, z int, string varchar(255), temp char(40) if (m < 1 and level > 0) then return "" end if let old = m call take_digit(m) returning m, z call take_digit(m) returning m, y call take_digit(m) returning m, x let string = "" if (x > 0 and x < 10) then let string = concat(ones[x], "Hundred") end if if (y) then if (y == 1) then let string = concat(string, ones[y*10 + z]) let z = 0 else let string = concat(string, tens[y]) end if end if if (z) then let string = concat(string, ones[z]) end if if (level >= 1 and string is not null) then let string = concat(string, units[level]) end if if (level == 0) then if (m == 0 and string is null) then let string = "Zero" end if let temp = old let x = length(temp) let temp = temp[x - 1, x] let string = concat(string, "and") let string = string, " ", temp clipped, "/100 Dollars" end if let string = concat(mtoa(m, level + 1), string) return string end function function take_digit(m) define m decimal(32, 2), x varchar(50), i int let x = m let m = m / 10 let i = length(x) return m, x[i-3] end function function concat(a, b) define a, b, c varchar(200) if (a) then let c = a clipped, " ", b return c else return b end if end function