Re: TRUNC Function Question
Posted in 1995
I don't have source for TRUNC at hand, but I do have this old source for ROUND: /* @(#)File: round.c @(#)Version: 1.1 @(#)Last changed: 89/06/06 @(#)Purpose: I4GL: Round Informix Decimal Numbers @(#)Author: J Leffler */ /* -- Include Files */ #include <stdio.h> #include <assert.h> #include <decimal.h> #ifndef lint static char sccs[] = "@(#)round.c 1.1 89/06/06"; #endif /* -- Routine: round */ int round(i) int i; { dec_t d; int n; assert(i == 2); popint(&n); popdec(&d); decround(&d, n); /* Undocumented function call */ retdec(&d); return(1); } However, if you change every occurrence of round into trunc, it will do the job. With some compilers, this command line would do the trick. cc -c -Dround=trunc -Ddecround=dectrunc -I${INFORMIXDIR}/incl round.c -o trunc.o Otherwise, use: sed s/round/trunc/g round.c > trunc.c cc -c -I${INFORMIXDIR}/incl trunc.c Use: LET d = ROUND(d, 3) -- Round d to 3 decimal places LET t = TRUNC(d, 0) -- Truncate d at 0 decimal places (convert to integer) Don't forget to add the functions to your custom runners if using p-code. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> >From: Tracy Nedd <tracyn@asd.banctec.com> >Date: Fri, 22 Dec 95 12:28:08 EST >X-Informix-List-Id: <list.8297> > >I've got what I hope will be a quick answer to an easy question: >Does anyone have a 4GL equivalent of the TRUNC function handy? >I have a client who doesn't have esql/c and doesn't know c, >that needs to do truncation in his 4GL. Any help is always >appreciated. Happy Holidays!