Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Code Snippets Code Examples

Calculate VAT on a price and round to two decimal places

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; }?>