Rounding

John Pearce jpearce@rmi.net
Sat, 30 Oct 1999 09:45:17 -0600


Terry Pickering wrote:
>Does anyone have ideas on how to force an amount that has been split over
>multiple records, to total EXACTLY to the original amount? Rounding doesn't
>appear to solve the problem.

Terry, I do something like what you want in a labor distribution QTP
process.  I can't get to the source code at the moment or I'd cut and paste
the relevant code.  Anyway... from memory:

access prwork &  ;prwork has one record per employee with total earnings
and taxes
  link to prhours    ;prhours has the hours charged to each department -
can be from 1 to n records
sorted on employee-no
temporary t-dist-total integer*8    ;total amount to be distributed
item t-dist-total reset at employee-no to distribution-amount of prwork

temporary t-dist-calc integer*8     ;distribution for the current prhours
record
item t-dist-calc = round(distribution-amount of prwork * (hours of prhours
/ hours of prwork))

temporary t-dist-final integer*8      ;distribution for output
item t-dist-final = t-dist-calc if t-dist-total > (t-dist-calc + 5) else
t-dist-total
;  this should write the remaining t-dist-total when the difference between
;  t-dist-total and t-dist-calc is less than 5 cents

output prdist add
item employee-no
item t-dist-final alias distribution-amount

item t-dist-total = t-dist-total - t-dist-final  ;reduce the total to be
distributed by 
                                                           ;the amount just
distributed

Since I'm doing this from memory, you should "test drive" the code in a
sample case.  If it works for you, I'll share the credit with Matt Ohmes as
he helped me develop this code in the first place.

Hope this helps.

John


---------------------------------------------------------------------------
John Pearce  <jpearce@rmi.net> 

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.