Calculating the reverse percentage with PHP.

This is a short guide on how to calculate the reverse percentage of a given number. i.e. You have the percentage number and the percentage, but you need to calculate the original number that it came from.

Take a look at the following PHP example, as the code will probably explain it better than words:

In the code snippet above, we know that 72,985 is 77% of X. However, we do not know what X is. X in this case is the original number that 72,985 came from.

In order to calculate the original number, we need to do a reverse percentage calculation and divide the percentage into the percentage value. The percentage value is often referred to as the final number.

Once we divide the percent into the final number, we simply multiply the result by 100. This gives us the original number.

Note that if you want the original number in a format that only has two decimal places, you can simply use PHP’s number_format function like so:

This leaves us with 94,785.71. This makes sense, as 72,985 is 77% of 94,785.71.

To sum up the terms above:

  • Final number: 72,985
  • Percent: 77%
  • Original number: 94,785.71

Hopefully, this guide helped to clear a few things up!

Facebook Comments