Extra decimal places?
Posted: Wed Dec 29, 2010 10:09 am
So I've got a fairly straightforward application where I'm pulling customer's invoices from the database. Under a given set of circumstances, a discount is to be applied. So as I'm looping through the entries on the invoice, I've got something like this:
Given that $cost is always rounded to 2 decimal places, I would expect $grand_total to also be two decimal places. Occasionally, however, I end up with a mess of 8 or 9 decimal places. Rounding the grand total fixes it, but any idea what's causing this? Seems like strange behaviour.
Code: Select all
...
$cost = round((($row['ccost'] * 0.95) + 0.0001), 2);
...
$grand_total += $cost