php - Get percentage between 2 numbers

Solution:

here is how you can do this

<?php

$yes = 130;
$no = 90;

$total_votes = $yes+$no;

if($total_votes > 0){
    $yes_percentage = ($yes/$total_votes) *100;
    $no_percentage = ($no/$total_votes) *100
}
else{
    $yes_percentage = 0; 
    $no_percentage = 0;

}

Answer

Solution:

First, you need to get total count.

$total = $yes + $no;

Then, if you want percentage of yes.

($yes / $total) * 100;

Answer

Solution:

percentage for YES

 Yes % = (total answers of yes / total ansers)*100
    $yes = 130;
    $no = 90;
    $totals = $yes+$no;
    $yes_per = ($yes/$totals) *100;

percentage for No

 No % = (total answers of No / total ansers)*100

    $no_per = ($no/$totals) *100

Answer

Solution:

TotalParticipants=130+90=220
YesVotedParticipants=130
NoVotedParticipants=90

YesVotedPaticipants percent(%)= (YesVotedParticipants/TotalParticipants)*100
                                 = (130/220)*100 =59.09 %

NoVotedPaticipants percent(%)= (NoVotedParticipants/TotalParticipants)*100
                                 = (90/220)*100 =40.90 %

Source