Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Percentage calculation

I am working in progress bar concept in ASP.NET MVC 2. Here i have a DropDownList which has 10 values. i want to calculate the percentage for progress bar, e.g. 10 values from DropDownList and i am having a query which returns the value 2. so, out of 10 values i am getting 2. "20 % completed" should be displayed.. How to do this calculation

like image 940
RobinHood Avatar asked Dec 30 '10 09:12

RobinHood


People also ask

How do I calculate a percentage between two numbers?

The percentage difference between two values is calculated by dividing the absolute value of the difference between two numbers by the average of those two numbers. Multiplying the result by 100 will yield the solution in percent, rather than decimal form.


2 Answers

Using Math.Round():

int percentComplete = (int)Math.Round((double)(100 * complete) / total); 

or manually rounding:

int percentComplete = (int)(0.5f + ((100f * complete) / total)); 
like image 79
Sogger Avatar answered Sep 19 '22 03:09

Sogger


(current / maximum) * 100. In your case, (2 / 10) * 100.

like image 28
Nicolas Repiquet Avatar answered Sep 22 '22 03:09

Nicolas Repiquet