Asked 7 years ago
15 Dec 2017
Views 3658
jabber

jabber posted

how to get percentage of value in php ?

i want to get percentage of value like i have 12345 total amount and 1200 amount is how much percentage of 12345 ?


$data1=12345;
$dataofdata1=1200;
$percent='';//want to find percentage


i trying following solution . but its not getting percentage

$percentInDecimal = $data1 / 100;
 
//Get the result.
$percent = $percentInDecimal * $dataofdata1;
 
//Print it out - Result is 232.
echo $percent;

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

$totalvalue is 100 percentage than how much percentage for $someofvalue ?

so multiply $someofvalue to 100 and divide it with $totalvalue

so equation is like =($someofvalue*100)/$totalvalue;

so


$data1=12345;
$dataofdata1=1200;
$percent=($dataofdata1*100)/$data1;
//round it 
echo round($percent);

Post Answer