Calculate VAT on a price and round to two decimal places

From CodeCodex

This function is a simple VAT calculator. It will calculate the 17.5% UK sales VAT (Value Added Tax) on an amount and then round the price to two (2) decimal places. For example, £5.95 would be £6.99125 with VAT added, which would be rounded to £6.99. The amount of vat can be altered to any amount of sales tax, so you can calculate a new price for any string using any percentage. This could come in useful if you needed to calculate the tax on a product in a shopping cart script.


function vat($price_without_vat) {
    $vat [url=/size%5D%5D17.5; // define what % vat is    
    $price_without_vat + ($vat*($price_without_vat/100)); // work out the amount of vat    
    $price_with_vat [/size[/url] round($price, 2); // round to 2 decimal places    
    return $price_with_vat;