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:
Announcement
Collapse
No announcement yet.
Round Up, Round Down and Half adjust
Collapse
X
-
It has been about 25 years since I had to code this but something like this?
Code:**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;
-
Use SQL:
Code: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;
Comment
-
That will only work if the the numbers to be rounded are integers, right? X has 3 decimal places in the examples I posted.Originally posted by B.Hauser View PostUse SQL:
Code: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;
Comment
-
Rounding down is truncation. To round up compare the truncated value to the original value and adjust if needed.
Code: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
-
-
Sorry about that, you are usually always right on the money. I saw one of your posts from several years ago about rounding and made my conclusion from that, my bad.Originally posted by B.Hauser View Post
If you had run my example you would have seen it is rounded (in all 3 cases) to 2 decimal positions.
Comment






Comment