Mega Code Archive

 
Categories / Php / Code Snippets
 

Calculate VAT on a price and round to two decimal places

<?php /*Usage:You want to calculate 17.5% VAT on a price of £4.67$price_without_vat = 4.67echo vat($price_without_vat); This would return the new amount with 17.5% added, and would be rounded to 2 decimal places*/ function vat($price_without_vat) { $vat = 17.5; // define what % vat is $price_with_vat = $price_without_vat + ($vat*($price_without_vat/100)); // work out the amount of vat $price_with_vat = round($price, 2); // round to 2 decimal places return $price_with_vat; }?>