PHP Salt


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

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
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:

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