Reputation: 738
I want to show the winning success rate between wins and loses I had a go with this
$percent = ($row['wins'] - $row['loses'] / (($row['wins'] + $row['loses']/2))* 100);
based on calculatorsoup.com % difference calculator formula
Calculate percentage difference between V1 = 15 and V2 = 6
( | V1 - V2 | / ((V1 + V2)/2) ) * 100
= ( | 15 - 6 | / ((15 + 6)/2) ) * 100
= ( | 9 | / (21/2) ) * 100
= ( 9 / 10.5 ) * 100
= 0.857143 * 100
= 85.7143% difference
but I think I'm going about it the completely wrong way, my goal is so output would be something like:
user bob has a success rate of: 17%
Upvotes: 1
Views: 1103
Reputation: 502
the math is quite simple if i understood the question: W = wins
L = loses
T = W+L
the winning rate in a proportion is W : T = X : 100.
in code
$w = $row['wins'];
$l = $row['loses'];
$rate = ($w * 100)/($w + $l)
Upvotes: 0
Reputation: 20514
If you want to show the success rate of a player this will be the code snippet:
$wins = 9;
$losses=3;
$succesRate = ( $wins/ ($wins + $losses) ) * 100 ;
//output will be "Success rate is: 75%"
echo "Success rate is:".$successrate."%" ;
Upvotes: 0
Reputation: 14681
It's the ratio number of wins / total tries:
$percent = 100 * $row['wins'] / ($row['wins'] + $row['loses']);
Upvotes: 3
Reputation: 34055
$v1 = $row[wins];
$v2 = $row[loses];
$percent = ( abs($v1 - $v2) / (($v1 + $v2)/2) ) * 100;
Upvotes: 0