...

# finding the percentage saved from 2 prices using php?

LJackson
02-12-2010, 05:50 PM
Hi All,

i have hundreds of products in my db all with different prices and offer prices and i am trying to work out how to get the percentage the user saves. but i was never any good at maths :(

for example

the original price is £220.99
the offer price is £200.99
difference of £20.00

but i have no idea how to work out the percentage saved?

can anyone help me with this please
many thanks

Luke

tomws
02-12-2010, 05:58 PM
This isn't a PHP problem. It's a 5th grade math problem. Google and Wikipedia are your friends.
http://en.wikipedia.org/wiki/Percentage

LJackson
02-12-2010, 09:52 PM
ok solved it thanks

this is the solution for anyone else
\$percentage = ( ( high price - low price ) / high price ) * 100;

hope this helps someone
:)

Len Whistler
02-12-2010, 10:45 PM
I would then round the results.

I don't have PHP running at the moment so I'm guessing that 9.050183266 would be 9.05
\$percentage = round((( high price - low price ) / high price ) * 100, 2);

-----------------------