Jump to content

Archived

This topic is now archived and is closed to further replies.

Canman2005

php percentages

Recommended Posts

Hi all

I 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 advance

Ed

Share this post


Link to post
Share on other sites
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.60
echo $total - ($total/100*20);

?>[/code]

Share this post


Link to post
Share on other sites
Or just do $total*0.8, that will give you the same effect but is just shorter.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.