$percentage = 50;
$totalWidth = 350;
$new_width = ($percentage / 100) * $totalWidth;
<?php
// How much is the x percentage of given value
$percentage = 10;
$totalValue = 500;
// 10% of 500
echo $newValue = ($percentage*$totalValue)/100;
// defining function
function calPercentage($num, $total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
return $count;
}
// call function to calculate percentage
echo "Percentage of 100 in 1000 = ".calPercentage(100, 1000).'%<br/>';
echo "Percentage of 26 in 200 = ".calPercentage(26, 200).'%<br/>';
echo "Percentage of 30 in 400 = ".cal_percentage(30, 400).'%<br/>';
Output
Percentage of 100 in 1000 = 10%
Percentage of 26 in 200 = 13%
Percentage of 30 in 400 = 8%
//ENTER PERCENT AND AMOUNT
//IT WILL RETURN OUTPUT
//INTAKE: 2% OF 10
//OUTPUT : 0.2
function calc_percent($percent, $amt) {
return $output = ($per/100 * $amt);
}
$percentage = 10; //persentage
$totalWidth = 1000; //Summa
$new_width = ($percentage / 100) * $totalWidth;