How to calculate the percentage of likes?

1

How can I find a way to calculate two values to arrive at a percentage, for example: I have 100 likes in one variable and 10 dislikes in another. In this example, (100 - 10 = 90)% of people who read it liked it ... This is a very simple example, but what if I had 90% likes and 921320201 dislikes, how would I do this? equation?

    
asked by anonymous 12.09.2017 / 00:09

2 answers

3

I applied the formula (likesPositive / totalLikes) * 100 = percentage

<?php 
$likesPositivos = 5000;
$dislikes = 2500; 
$totalLikes = $likesPositivos + $dislikes;

$porcentagem = ($likesPositivos/$totalLikes) * 100;

echo $porcentagem;
    
12.09.2017 / 00:29
1

You want to know what the occurrence of a particular characteristic is in a set. If every element has equal weight, the formula is:

Contagem de indivíduos com a característica / total de indivíduos 

In this case, you have two disjoint types of individuals:

  • like
  • dislike

So we can turn the formula into:

likes / (likes + dislikes)

In this case, we get a number between [0,1] . That is the ratio in absolute terms. To get it in percentage terms, simply multiply the result by 100.

Do not forget to make the operation with real numbers instead of the whole division.

According to this post , PHP already works with real division by default. According to this post , JavaScript also works like this.

    
12.09.2017 / 00:24