PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.14.1
Last Build: March 10, 2017 13:28pm (PST)

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:


See Also

And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site