Jump to content


Photo

php percentages


  • Please log in to reply
2 replies to this topic

#1 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 28 March 2006 - 08:43 AM

Hi all

I have a calculation that I do, it look like

<?php

$subtotal = 33;
$delivery = 45;
$total = $subtotal + $delivery;

echo $subtotal;

?>

How could I remove 20% from the $total? So it would look something like

$total = $subtotal + $delivery + 20%;

Is this easy to do?

Thanks in advance

Ed

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 March 2006 - 09:20 AM

You'll want to do this:
<?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.60
echo $total - ($total/100*20);

?>


#3 Eddyon

Eddyon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationEngland

Posted 28 March 2006 - 12:04 PM

Or just do $total*0.8, that will give you the same effect but is just shorter.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users