Reputation: 6252
I believe this is a language agnostic question and more focused on math, however I prefer PHP. I know how to calculate percentages the normal (forward) way:
$percent = 45.85;
$x = 2000000;
$deduction = ($percent / 100) * $x; // 917,000
$result = $x - $deduction; // 1,083,000
What I would like to do, is be able to reverse the calculation (assuming I only know the $percent
and $result
), for example...
54.15% of x = 1,083,000
How do I calculate x? I know the answer is 2,000,000, but how do I program it to arrive at that answer?
I found a similar question & solution through Google but I just don't understand how to implement it...
Upvotes: 0
Views: 1455
Reputation: 4334
When you say 54.15% of x = 1083000, you mean 0.5415 * x = 1083000. To solve for x, divide 0.5415 from both sides: x = 1083000 / 0.5415. The PHP is:
$p = 54.15;
$r = 108300;
// First, make p a number, not a percent
$p = $p/100; // I would actually use $p/= 100;
// Now, solve for x
$x = $r/$p;
Upvotes: 0
Reputation: 14921
You can do
1,083,000 * 100 / 54.15
In PHP, it will be
$x = $result * 100 / $percent
Upvotes: 3