x1nick Posted November 11, 2009 Share Posted November 11, 2009 Feel so stupid asking this because its so simple. But having nothing but trouble with it! Basically I can't calculate VAT properly 100% of the time. Every now and again the price will be out by 1p May not be much, but its incorrect. The code im using <?php $price = 68.69; $vat = 15; echo round($price * (($vat / 100) + 1), 2); ?> If the price is set at 68.69 or 68.70 you will see the outcome is either 78.99 or 79.01 Making it impossible to get 79.00 Is there any way round this? Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 11, 2009 Share Posted November 11, 2009 You could use floor or ceil (there might be legal regulation concerning which should be used). Quote Link to comment Share on other sites More sharing options...
cags Posted November 11, 2009 Share Posted November 11, 2009 I remember when the VAT was lowered from 17.5% to 15%, I was working as a salesman at the time. Customers assumed that every product would then be x amount cheaper, but it just didn't work like that. As we were a electronic goods retailer, prices were calculted using trade + desired markup + vat then normally rounded to the nearest £50. Due to it being rounded the price didn't actually change in many cases, (which obviously customer saw as us robbing them) despite the fact we were not making desired markup in many cases because the nearest £50 was rounding down. Since most prices are displayed inclusive of vat, its quite difficult to change when the VAT value changes. For neatness prices generally are to the closest £1, yet people still expected you to divide the old price by 1.175 then multiply by 1.15. Long story short, for that reason our epos system actually calculated it backwards, you put in how much your charging and it calculated how much of it was VAT. Not entirely relevant I guess but it's a simpler way of handling VAT. In your current method I suspect most people would use ceil so that every part penny rounds up to a penny. Quote Link to comment Share on other sites More sharing options...
x1nick Posted November 25, 2009 Author Share Posted November 25, 2009 Still can't get this to work! function calc_vat($value,$vat) { $prec = 0.01; if (is_numeric($value) && is_numeric($vat)) { $value = $value * (($vat / 100) + 1); $retval = ceil($value/$prec) * $prec; } else{ $retval = false; } return $retval; } Results: 42.6 = 48.99 42.61 = 49.01 42.62 = 49.02 Anyone got any suggestions? Quote Link to comment Share on other sites More sharing options...
cags Posted November 25, 2009 Share Posted November 25, 2009 Is the value always going to round to the pound? If so something like this should do. round($value, 1); Quote Link to comment Share on other sites More sharing options...
x1nick Posted November 25, 2009 Author Share Posted November 25, 2009 Its not always to the pound, only on a selection of products Quote Link to comment Share on other sites More sharing options...
cags Posted November 25, 2009 Share Posted November 25, 2009 Well that being the case you need a distinct logical methodology. What values don't round to the nearest pound, and what distinguishes them from the ones that do? Quote Link to comment Share on other sites More sharing options...
christalix Posted November 27, 2009 Share Posted November 27, 2009 here -------> use this function getprice($price) { $res = $price * 1.19; //where 1,19 is the tax rate return $res; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.