How do I make the valuation account

0

I'm going crazy here already trying to figure out how I do the bill to get results for me to make a progress bar like this.

There in the bar of 5 stars has 100% in the of 4 has 20% as I get in these results.

Division ?? I got the result of those 4.4 there, plus for each bar I'm not getting ..

    
asked by anonymous 04.01.2016 / 01:22

1 answer

2

You need to know:

  • Maximum possible score
  • number of votes
  • quality of votes

In variables could be:

$quantidadeVotos = 15 + 3 + 2;
$qualidadeVotos = 5*15 + 4*3 + 1*2;

So that the maximum score is 5, and thinking that the maximum score would be $quantidadeVotos * 5 , you can do:

$quantidadeVotos * 5     5
____________________  = ___

  $qualidadeVotos        ?

Then you can solve with:

$resultado = $qualidadeVotos / $quantidadeVotos;

ie in this example you have:

$resultado = (5*15+4*3+1*2) / (15 + 3 + 2); // 4.45
    
04.01.2016 / 01:41