dcjones wrote:Hi all,
I am going round the twist trying to solve this problem.
I want to do some calculations as follows:
Total = £12.00
VAT = 17.5%
Total - VAT =
$total = 12.00;
$vat = 17.5;
$net_total = $total - $total * ($vat / 100);
echo round($net_total, 2);
This code results in displaying 9.9 but it should be 10.21.
Can anyone see where I am going wrong.
Your math is all wrong. 17.5% of 12.00 is 2.10. From 12.00 that leaves a remainder of 9.90 just like PHP says. Why do you think it should be 10.21? Are you trying to figure out how much to price an item so that WITH VAT it will equal $12? If so you are going about it all wrong.
The total price is 117.5% of the base price, correct? (100% base price + 17.5% VAT). Expressed as an equation: 1.175*price=total. If you have the total (12) and want to get the price, you need to balance the equation, so price=total/1.175. So price = 12 / 1.175, or price = 10.21
In PHP:
$total=12; $vat=17.5;
$net = $total / ( ($vat / 100) + 1 );
echo round($net,2);