psWhatPercent() Returns the percentage of a number from total.
Description:
This is for trying to figure out What Percent something is
That is, what percent is 5 out of 100. (fyi, its 20%)
Usage:
$p = psWhatPercent($num,$total{,$dec}); $num = a number out of $total $dec is decimal places (default is 1)
Example:
$p = psWhatPercent(5,100); // $p will be 20
Code:
function psWhatPercent($num,$total,$dec=1) { $places = $dec * 10; $res = 100 / ($total / $num); $res = floor($res * $places) / $places; return $res; }
Changlelog:
|
|