Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: finding the percentage saved from 2 prices using php?

1. ## finding the percentage saved from 2 prices using php?

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

• 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

• ok solved it thanks

this is the solution for anyone else
PHP Code:
``` \$percentage = ( ( high price - low price ) / high price ) * 100;  ```
hope this helps someone

• 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
PHP Code:
``` \$percentage = round((( high price - low price ) / high price ) * 100, 2);  ```

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

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•