Does anyone know of a method, routine, procedure, bif, etc. to perform round up or round down (not to be confused with half adjust) . The chart below shoes the difference between round up, round down and half adjust:
**free dcl-s rounded packed(5:2); dcl-s base packed(5:3) inz(12.999); dcl-s i int(5); for i = 1 to 100; eval(h) rounded = base + 0.004; dsply ( 'Base = ' + %char(base) + ' rounded = ' + %char(rounded) ); base += 0.001; endfor;
With x (Number) as (Values(430,123), (430,125), (430,128)) Select Number, Round(Number, 2) "Round", Ceiling(Number * 100) /100 "Round Up", Floor(Number * 100) / 100 "Round Down" from X;
With x (Number) as (Values(430,123), (430,125), (430,128)) Select Number, Round(Number, 2) "Round", Ceiling(Number * 100) /100 "Round Up", Floor(Number * 100) / 100 "Round Down" from X;
dcl-ds; x zoned(5:3) pos(1); x_trunc zoned(5:2) pos(1); end-ds; dcl-s result zoned(5:2); // rounding down x = 430.123; result = x_trunc; // result = 430.12 x = 430.125; result = x_trunc; // result = 430.12 x = 430.128; result = x_trunc; // result = 430.12 // rounding up x = 430.123; if x > x_trunc; result = x_trunc + .01; // result = 430.13 endif; x = 430.125; if x > x_trunc; result = x_trunc + .01; // result = 430.13 endif; x = 430.128; if x > x_trunc; result = x_trunc + .01; // result = 430.13 endif;
Comment