Re: Rounding decimal variables
Posted in 1999
Jacek Medrzycki wrote: > > Hi all! > > Informix 7.22.UC2 > > R4GL 6.05.UC1 > > The following program: > > MAIN > > DEFINE aaa DECIMAL(14,2) > LET aaa = 650.2646 > DISPLAY aaa > > END MAIN > > gives the result: 650.26 instead of 650.27. It looks like 4GL just > truncates, not rounds the decimal value. > I don't think so. 650.2646 rounds down to the nearest hundredth -- 650.26, which is what I would expect. > But, the same program, but with different assignment: > > LET aaa = 650.265 > > gives the correct output: 650.27 . So in this case it rounds the value, > not truncates. > As expected; it rounds up to the nearest hundredth. > It looks like if, while rounding the value to match the precision, > Informix takes only n-th + 1 decimal position, where n is the > destination variable precision, and ingnores any following deciamal > positions. > > Is my assumption correct? Is this a bug or normal behavior? What should > I do to correctly round decimal values? > I'm not sure, but rounding seems to work as I would expect it. John Carlson Informix DBA WHSmith USA