<?php
$amount = 500;
$percentage = 20;
$percentage_value = calculateReversePercentage($amount, $percentage);
echo "$percentage% of $amount (Includes) = $percentage_value";
$percentage_value = calculateForwardPercentage($amount, $percentage);
echo "<br/>$percentage% of $amount (Not Includes) = $percentage_value";
function calculateReversePercentage($amount, $percentage) {
$percentage = round(($percentage / ((100 + $percentage) / $amount)) * 1, 2);
return $percentage;
}
function calculateForwardPercentage($amount, $percentage) {
$percentage = ($amount * $percentage) / 100;
return $percentage;
}
Which will output as below:
20% of 500 (Includes) = 83.3320% of 500 (Not Includes) = 100
No comments:
Post a Comment