Calculate percentage of up votes
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
$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)?
if(($upvotes+$downvotes) != 0) $percentage = (float)($upvotes/($upvotes+$downvotes))*100; else $percentage = 0;