Reputation: 207
I have two variables:
$percent = '3.5'; //this is the percentage
$order = 400;
//so how would i get $percent of $order?
Now in PHP how would I find out what 3.5% of 400 is (I know its 14) - but would like to know how to calculate it directly in PHP using those two variables above.
Appreciate your response.
Upvotes: 1
Views: 322
Reputation: 146310
You could make a percentOf
function:
function percentOf($number, $percent){
return $number * ($percent / 100);
}
//then:
echo percentOf($order, $percent);
Demo: http://codepad.org/a6BgEEs2
Upvotes: 2
Reputation: 191779
"Percent" just means "per 100" or "over 100" or "/ 100"
$percentOfOrder = $order * ($percent / 100);
Upvotes: 6