Re: Truncating Result for reporting
Posted in 1997
On Wed, 10 Dec 1997, Jochen Lorenz wrote: > tips to formatting numbers are send for you by Dennis Pimple (Informix). > But if you want to select a scope from a number, > i.e. > 24536.8746 to 24500 > therefore is the SQL-statement TRUNC. > Use so: > TRUNC (24536.8746,-2) => 24500 > or > TRUNC (24536.8746,0) => 24536 > and so on ... All correct. > There is no rounding ..... Oh, but there is rounding... On any version where TRUNC is supported, the ROUND function is also supported. You can omit the second argument in both ROUND and TRUNC because it defaults to 0. You can also TRUNC or ROUND to positive numbers of decimal places... This is arithmetic rounding rather than financial rounding, which is more complex. With arithmetic rounding ROUND(75.5,0) = 76 and ROUND(74.5,0) = 75 so the 0.5 value is rounded up. With financial rounding: ROUND(75.5,0) = 75 and ROUND(74.5,0) = 75 so that if the value preceding the 0.5 is an odd digit, it is rounded down, but if it is an even digit, it is rounded up. Or it could be the other way round, in which case the comparison to 76 and 74 would be correct. The significance of the financial rounding is that it is less likely to accumulate errors if a bunch of values are all rounded. > >Can someone teach me how to truncate a mathematics calculation for > >reporting purposes? > > > >Katherine > >email : ieplved@singnet.com.sg Yours, Jonathan Leffler (johnl@informix.com) #include <witticism.h>