Re: 4gl round function???
Posted in 1997
On 23 Apr 1997, Joseph Cullipher wrote: > Hi all, > I am in need of a round function for 4gl. I am currently using 6.00 and > haven't found one in my manuals or release notes. I have found out that > if I use the using clause it will round. > > let smallint=3-(7/4) using "<" I haven't benchmarked it, but would guess that that using clause there is a moderately expensive operation. Informix always truncates real numbers when placing them into a smallint. The easiest way to change this is to allow Informix to work the same way -- ie truncating -- but apply additional logic to it. Standard rounding rounds up (the difference) if the decimal portion is => .5. Therefore: LET f_smallint = (real_number_or_expression) + .5 works by identifying the incorrectly treated portion of the original and fixing it with a minimal amount of overhead. Similarily, if you want to always round the answer to a particular expression upwards (very common) you might choose: LET f_smallint = (real_number_or_expression) + .99999 using (1 + precision of real) 9s. This forces all numbers not integers to round up. Note that there may be a few glitches when the precision desired approaches the maximum precision available on your platform. -Richard