Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating Discount Percentage of a given discounted price

Tags:

php

math

I am trying to find out the discount amount of a price.

The cost of item WAS £50.00 Sale Price £25.00 Discount = %50

However when use this formula below in PHP it doesnt give me the correct Discount percentage.

$percent = $rowx->Orgprice - $rowx->SalePrice / 100;
$percent =  50 - 25 / 100 = 49.75; 
$percent =  50 - 20 / 100 = 49.8;

All above percentages are wrong.

like image 589
Aslan Kayardi Avatar asked May 01 '17 14:05

Aslan Kayardi


People also ask

What is the formula for calculating discount?

To calculate the discount, just multiply the rate by the original price. To compute the sale price, deduct the discount from the original price. Solution: Given that the rate is 10%.


2 Answers

Use this formula for calculating the discount percentage :

Discount%=(Original Price - Sale price)/Original price*100

Translating it into code, it should be something like :

$percent = (($rowx->Orgprice - $rowx->SalePrice)*100) /$rowx->Orgprice ;
like image 129
Reuben_v1 Avatar answered Oct 20 '22 00:10

Reuben_v1


selling price = actual price - (actual price * (discount / 100))

So for example if (actual price) = $15, (discount) = 5%

selling price = 15 - (15 * (5 / 100)) = $14.25
like image 39
Zione01 Avatar answered Oct 20 '22 01:10

Zione01