Simple PHP math problem trying to get a percentage and failing at it.
Posted on 2013-06-29
I'm sorry to have to ask. I should've listened up in math class:
I'm comparing open rates for 2 different email campaigns.
$current_campaign = 3
$previous_campaign = 2
So I'm trying to do the math to show what percentage of increase or decrease the current campaign has compared to the previous. Seemed simple enough when I started....
My math is:
$sent_percent = number_format(($previous_campaign / $current_campaign) * 100 - 100,0);
This echos out: -33% where based on the above it should actually be a 33% increase (no negative sign)
If I take out the '-100' in the formula, I get 67% but that isn't how much of an improvement the current campaign is compared to the previous. See what I mean?
This can't be that hard and I'm chalking it up to my inexperience and failure to take math seriously in high school.