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

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)?

Answers


Simply

    if(($upvotes+$downvotes) != 0)
    $percentage = (float)($upvotes/($upvotes+$downvotes))*100;
    else
    $percentage = 0;

Need Your Help

Change the naming style in Resharper from a config file

c# visual-studio-2013 resharper naming-conventions

Is there any issue to write the "Naming Style" rules in a file and then load them in Resharper ??

Firefox add-on local area network communication capabilities

firefox firefox-addon-sdk lan network-interface

I would like to develop a firefox extension that communicates with other firefox extensions in the same LAN.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.