Re: Rounding decimal variables
Posted in 1999
Jacek Medrzycki wrote: > > Carlson@WHSmith wrote: > > > > > I don't think so. 650.2646 rounds down to the nearest hundredth -- > > 650.26, which is what I would expect. > > > > > > But I need a "precise" rounding, according to mathematical rule: when value > on n-th decimal position is bigger or equal to 5, then the n-th - 1 position > in incremented by one - and so on... So 650.2646 --> 650.265 --> 650.27 > > Is there a built-in function to make such a rounding, or should I write my > own one? Sorry Jacek but 4GL is correct and you are in correct. Rounding NEVER cascades. If you are rounding to the nth digit you only look to see if the n+1st digit is >=5 since 4.6 is less than 5 4GL is doing it right. If you want to get rounding to the n+1st digit try adding 0.0005 to the value before display it will give you the results you seek. There is an old programmers' trick, being an old programmer I'd know about such stuff, to avoid the uncertainties of binary floating point and add 5 to the n+2nd digit before rounding but that's another story. Art S. Kagel