Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quick RPG ILE programming question re: Rounding

3,023 views
Skip to first unread message

Barb

unread,
Jun 4, 2001, 5:16:49 PM6/4/01
to
I've been asked by the accounting dept to generate some report totals based
on some input files. However, they want totals to be rounded based on
.50...(>.5 :round up, <.5:round down).

Each record has about 9 amount fields. Is there a way, without testing each
field, to have RPG round in the way that they want?

I can only get it to round up. {H- half adjust}

Thanks so much

~Barb


Ugo Gagliardelli

unread,
Jun 4, 2001, 7:12:01 PM6/4/01
to

Barb wrote:
>
> I've been asked by the accounting dept to generate some report totals based
> on some input files. However, they want totals to be rounded based on
> .50...(>.5 :round up, <.5:round down).
>
> Each record has about 9 amount fields. Is there a way, without testing each
> field, to have RPG round in the way that they want?

No.


> I can only get it to round up. {H- half adjust}

True.
Make a func that adds .5 then move the result into an integer.
eg 100.1 + .5 = 100.6 -> 100
100.6 + .5 = 101.1 -> 101
--
Dr. Ugo Gagliardelli, Modena, Italy
Spaccamaroni andate a cagare/Spammers not welcome
Spamers iros a la mierda/Spamers allez vous faire foutre
Spammers loop schijten

Ken S.

unread,
Jun 4, 2001, 7:19:00 PM6/4/01
to
Hi Barb -

You did not say what should happen to .50. If you want .50 to round
up like the values above .50, then half-adjust does what you want. If
you want .50 to stay at .50, .51 to .99 to round up, and .01 to .49 to
round down, then I would suggest writing a subprocedure to do it.

Ken
http://www.ke9nr.org/
Opinions expressed are my own and do not necessarily represent the views of my employer or anyone in their right mind.

Barbara Morris

unread,
Jun 4, 2001, 7:42:10 PM6/4/01
to
Barb,
Half-adjust is supposed to do the kind of rounding you want. 2.50 and 1.49
rounded to zero decimal places should be 2 and 1.

Here's a little program that I ran in the debugger. After each eval(h) I
checked
"result" and the results were rounded as you describe.

D num s 5p 2
D result s 5p 0
C eval num = 1.49
C eval(h) result = num RESULT = 00001.
C eval num = 1.50
C eval(h) result = num RESULT = 00002.
C eval num = 1.51
C eval(h) result = num RESULT = 00002.
C seton

Can you post a similar little program that illustrates the problem you're
having? You're probably doing something more complicated than assigning one
value to another.

If you try to handle this yourself by adding .5 as Ugo suggests, be careful with
negative numbers (you have to add -.5 unless you want very strange rounding).

- Barbara

0 new messages