Calculate percentage of up votes

Posted by MakuraYami on Stack Overflow See other posts from Stack Overflow or by MakuraYami
Published on 2012-04-05T10:05:07Z Indexed on 2012/04/05 11:29 UTC
Read the original article Hit count: 180

Filed under:
|
|

I have searched this site and Google and even though the idea is pretty simple I can't figure it out.

I need to (like seen on YouTube) calculate the % of up-votes based on the amount up-votes and down-votes.

I have two vars, $upvotes and $downvotes now i need to calculate $ratio

For example

$upvotes = 3;
$downvotes = 1;

The ratio here needs to be 75 (%)

If you have

$upvotes = 0;
$downvotes = 100;

It needs to be 0 (%)

How do I calculate the percentage (in PHP)?

© Stack Overflow or respective owner

Related posts about php

Related posts about math