Jump to content

php percentages


Canman2005

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
Link to comment
https://forums.phpfreaks.com/topic/5993-php-percentages/
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]
Link to comment
https://forums.phpfreaks.com/topic/5993-php-percentages/#findComment-21493
Share on other sites

Archived

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

×
×
  • Create New...

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.