user2306309
user2306309

Reputation: 541

Math task, convert 10 star rating to up and downvotes

i want to change my articles rating-script from 10 stars rating (gdsr) to up and downvotes (like youtube).

But i dont want to loose my current ratings, so my idea is to convert the current (10 stars gdStarRating) to up and downvotes.

My problem is the math formula ... i dont get it.

for example

10 members has voted, the rating is 9
= 9 upvotes and 1 downvote

another example

18 member has voted, the rating is 9.6
=  ?? upvotes and ?? downvotes

or

15 member has voted, the rating is 8.8
=  ?? upvotes and ?? downvotes

What is the correct (PHP) math formula ?

Upvotes: 2

Views: 197

Answers (1)

FuzzyTree
FuzzyTree

Reputation: 32402

Multiply the rating ratio by the # of total votes to get the up/down ratio that's closest to your current vote/10 ratio

i.e.

18 member has voted, the rating is 9.6
=  ?? upvotes and ?? downvotes

a rating of 9.6 translates into 96% upvotes, 18 * 96% = 17.23 => 17 up votes 1 down vote

15 member has voted, the rating is 8.8
=  ?? upvotes and ?? downvotes

a rating of 8.8 translates into 88% upvotes, 15 * 88% = 13.2 => 13 up votes 2 down votes

PHP example

$totalvotes = 18;
$rating = 9.6;
$upvotes = round($totalvotes * ($rating/10));
$downvotes = $totalvotes - $upvotes;

Upvotes: 3

Related Questions