the_unforgiven_II
the_unforgiven_II

Reputation: 361

Adding a percentage (%) to a price with PHP

I am wanting to know how to show a 3% surcharge in one column then add that to the total price

I have a variable set up $percent = '0.03'; which is 3% right?

Then have this in my total col - printf("%.2f", $invoice['invoice_amount'] + $percent); but it's only adding 3pence and the actual total in this case with the 3% surcharge would be £190.55 according to Google!

How can I just show what percentage is been added to in this case would be 5.55

Please help me, I'm going round in circles!

Upvotes: 0

Views: 1558

Answers (3)

Geoffrey Burdett
Geoffrey Burdett

Reputation: 1976

Add $percent back into the invoice amount Try something like

printf("%.2f", $invoice['invoice_amount'] + ($invoice['invoice_amount'] * $percent));

Upvotes: 2

nowhere
nowhere

Reputation: 1548

$p=$invoice['invoice_amount'] * $percent;
printf("%.2f", $invoice['invoice_amount'] + $p);

Upvotes: 2

Riggy
Riggy

Reputation: 1387

You need to multiply the invoice amount by the percent and then add that result back to the original invoice amount.

Upvotes: 0

Related Questions