Re: Help w/ this lit'l function
Posted in 1996
You might want to RTFM (and test a little) on how the clipped keyword works. See below: hfiabema@osf1.gmu.edu (Hannah Sobie Fiabema) wrote: :Gurus, : I am having a little proble w/ this function. It is SUPPOSED to :accept an argument of type Money, and return the ascii equivalent :minus the dollar sign and decimal point. Everything almost works except :it is NOT returning the Cents portion of the argument. : Thanks for any and all help. Here is the code: :FUNCTION MoneyToString(MoneyAmt) :DEFINE StringAmt CHAR(20), : DolarAmt CHAR(20), : CentsAmt CHAR(20), : cMoneyAmt CHAR(20), : MoneyAmt Money(12,2), : StrLen integer : initialize dolaramt, centsamt to null : IF MoneyAmt IS NOT NULL THEN : LET cMoneyAmt = MoneyAmt The following is a noop: : LET cMoneyAmt = cMoneyAmt clipped : LET StrLen = LENGTH(cMoneyAmt) : LET DolarAmt = cMoneyAmt[2,(StrLen-3)] : display "dolaramt...",dolaramt : LET CentsAmt = cMoneyAmt[(StrLen-2),StrLen] : display "centsamt...",centsamt : sleep 2 : LET StringAmt = DolarAmt clipped : IF CentsAmt IS NULL THEN : display "NULL yes..." : LET StringAmt = DolarAmt, "00" : ELSE : LET StringAmt = DolarAmt, CentsAmt Instead of the above try: LET StringAmt = DolarAmt clipped, CentsAmt The problem is that all these three variables are char(20). When you concatenate two of them without clipped the result becomes 40 character long. This is cut to 20 characters when inserted into StringAmt and you loose your CentsAmt. : END IF : --LET StringAmt = StringAmt clipped : display "stringamt...",stringamt : sleep 2 : end if : RETURN StringAmt :END FUNCTION I have *not* checked for other problems after I saw the one described. Not even the general functionallity of your function. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org