I'm wondering if I found an issue with the rounding in PHP, specifically 5.2.3 (I'm not sure about other versions at the moment):
$t = 0;
$taxAmount = (5.000 / 100) * 0.7;
$t += $taxAmount;
var_dump($t); // float(0.035)
var_dump(round($t, 2)); // float(0.03)
var_dump(number_format($t, 2)); // string(4) "0.03"
To me 0.035 should round to 0.04 or am I just crazy?
Edit
Thxs to NebyGemini's answer, I figured I would do this instead:
$t = 0;
$taxAmount = bcmul(bcdiv(5.000, 100, 3), 0.7, 3);
$t += $taxAmount;
var_dump($t); // float(0.035)
var_dump(round($t, 2)); // float(0.04)
var_dump(number_format($t, 2)); // string(4) "0.04"
Which works perfect.
BTW, I'm calculating a tax in a shopping cart. The order total is the 0.70 (70 cents) and the tax is 5%.
Edit
Thxs to Ignacio Vazquez-Abrams's answer, this is to show where the problem lies:
printf('%.18F', 5.000 / 100 * 0.7);