Canman2005 Posted March 28, 2006 Share Posted March 28, 2006 Hi allI have a calculation that I do, it look like[code]<?php$subtotal = 33;$delivery = 45;$total = $subtotal + $delivery;echo $subtotal;?>[/code]How could I remove 20% from the $total? So it would look something like[code]$total = $subtotal + $delivery + 20%;[/code]Is this easy to do?Thanks in advanceEd Quote Link to comment https://forums.phpfreaks.com/topic/5993-php-percentages/ Share on other sites More sharing options...
wildteen88 Posted March 28, 2006 Share Posted March 28, 2006 You'll want to do this:[code]<?php$subtotal = 33;$delivery = 45;$total = $subtotal + $delivery;echo 'Subtotal: ' . $subtotal . '<br />';echo 'Total: ' . $total . '<br />20% off: ';//take 20% off from $total, 20% of $total is 15.60echo $total - ($total/100*20);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5993-php-percentages/#findComment-21493 Share on other sites More sharing options...
Eddyon Posted March 28, 2006 Share Posted March 28, 2006 Or just do $total*0.8, that will give you the same effect but is just shorter. Quote Link to comment https://forums.phpfreaks.com/topic/5993-php-percentages/#findComment-21539 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.