White_Lily Posted October 13, 2012 Share Posted October 13, 2012 I have a CMS and it has a Commerce section, what I need it to do is calculate what the product price is, including VAT. I have written the function that does this, however the problem Im having is its outputting the wrong (in terms of decimal places). here is the function: //Price + VAT function getPriceVAT($price) { $vatValue = 20; $vat = $price / 100 * $vatValue; //Therefore price including VAT = $priceIncVAT = $price + $vat; return $priceIncVAT; } here is how im outputting it: echo '<td>£'.getPriceVAT($getFig["product_price"]).'</td>'; It calculates it correctly but to only 1dp. which outputs: £2.4 instead of: £2.40 how can i correct this? Quote Link to comment https://forums.phpfreaks.com/topic/269437-product-prices-vat/ Share on other sites More sharing options...
requinix Posted October 13, 2012 Share Posted October 13, 2012 (edited) printf() or money_format(), such as printf('<td>£%.2f</td>', getPriceVAT($getFig["product_price"])); Edited October 13, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/269437-product-prices-vat/#findComment-1385042 Share on other sites More sharing options...
White_Lily Posted October 13, 2012 Author Share Posted October 13, 2012 Thank you Printf worked, however money_format() apprently doesnt exist, and it broke the rest of the script. Quote Link to comment https://forums.phpfreaks.com/topic/269437-product-prices-vat/#findComment-1385044 Share on other sites More sharing options...
requinix Posted October 14, 2012 Share Posted October 14, 2012 FYI the next step down from money_format() is number_format(). Quote Link to comment https://forums.phpfreaks.com/topic/269437-product-prices-vat/#findComment-1385058 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.