Accounting for rounding errors

Status
Not open for further replies.

squibs

New Member
I posted this as an accountancy question on another forum. Perhaps it is more of a coding issue.

I'm writing an invoicing system in PHP/mySQL at the moment, for my own use, to suit my own business rules. A major premise is that when a quote is accepted, the invoices are generated from that quote, as stage-payment percentages of the overall cost. There can be as many stages as required, each with an abitrary percentage specified (not exceeding 100, obviously).

If I quote somebody for €1075.50 and invoice them in 3 stages for 17%, 50% and 33% of the total, these values work out at
182.83500000
537.75000000 and
354.91500000

On an invoice, I believe nobody issues invoices for a fraction of a penny, so these would be rounded to the penny, giving
182.83
537.75 and
354.91
if I round down giving a total invoiced of 1075.49, and

182.84
537.75 and
354.92
if I round up giving a total invoiced of 1075.51

Both these values differ from the quote value of 1075.50
How can I reconcile the error?


I could calculate when the last invoice had reached 100 percent and make it's value = totalcost - amount already invoiced. But this adds an unwieldy special case with lots of extra programming.

Can anybody suggest a more elegant solution?
 

d-tour

New Member
The answer sometimes aint in the software but the way you look at the problem.
value = totalcost - amount is the only way im afraid, but it shouldnt be that much more php.
Just add an extra field in your table for amount paid and update this for every payment.
 
Status
Not open for further replies.
Top