I could never think it would be even challenging but is there any function to calculate a percentage of a number or do I have to write a custom function?
Example:
$result=percent(25,100); //doing the 100%25 operation
$result = 4
I could never think it would be even challenging but is there any function to calculate a percentage of a number or do I have to write a custom function?
Example:
$result=percent(25,100); //doing the 100%25 operation
$result = 4
function percentage($part, $whole = 100) {
settype($part, "float");
settype($whole, "float");
$formule = ($part / $whole) * 100;
return $formule . " %";
}
echo percentage(25); // returns 25 %
echo percentage(91.8, 176); // returns 52,15909090909091 %
Voila ;-) Could be improved more, but i saw that you figured it out for yourself, so not needed anymore..