stublackett Posted June 11, 2008 Share Posted June 11, 2008 Hi, I'm not sure how to work this, I think its best as a function but any suggestions or directions to where I can get help for this would be much appreciated What I'm trying to do is calculate a new total price when a discount code is entered So for instance : Item total is £100 An item code is entered (Its always going to be 10% Discount) so the total with the new discount will be £90 (£10 Discount) How can I use PHP To calculate this? Any help appreciated :) Link to comment https://forums.phpfreaks.com/topic/109743-percentages/ Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 $total = 100; $discount = 0.1; $newtotal = 100 * (1 - $discount); echo $newtotal; Easy, no? As a function: function discount($total, $discount); { return $total * (1 - $discount); } Link to comment https://forums.phpfreaks.com/topic/109743-percentages/#findComment-563168 Share on other sites More sharing options...
stublackett Posted June 11, 2008 Author Share Posted June 11, 2008 $total = 100; $discount = 0.1; $newtotal = 100 * (1 - $discount); echo $newtotal; Easy, no? As a function: function discount($total); { return $total * (1 - $discount); } Very easy Muchos Gracias!! Link to comment https://forums.phpfreaks.com/topic/109743-percentages/#findComment-563170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.