简体   繁体   中英

Struggling with maths... How to reverse calculate a percentage?

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...

You can do

1,083,000 * 100 / 54.15

In PHP, it will be

$x = $result * 100 / $percent

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;

You divide. 1,083,000 / 54.15% is 2,000,000.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM