views:

210

answers:

6

I am using a JS progress bar that is set using a percentage: 0 to 100 (percent). I need the progress bar to reach 100% when 160,000 people have signed a certain form. I have the total number of signers set in a PHP variable but am lost on how to do the math to convert that into a percentage that fits within 1 - 100 (so that the progress bar actually reflects the goal of 160,000).

I may be missing something obvious here (i suck at anything number-related) so does anyone here have a clue as to how to do this?

A: 

If N is the goal, and X is the number of people that have signed so far, then the percentage is (X/N)*100.

duffymo
+1  A: 

Just

percentage = number/160000 * 100
David Zaslavsky
A: 

...you can't convert a number to a percentage?

$percent = ($currentNumber / 160000) * 100; 

If you don't want a float answer you can just cast or round it however you'd like.

Paul
A: 

160,000/160,000 = 1 = 100%

160,000/2 = 0.5 = 50%

Given this, the calculation should be easy. The numerator is the number completed and the denominator is the "goal" -- the total to complete.

So once you are 80,000 you'd be 50% complete and your progress bar would render as such.

If you need to work with smaller numbers, divide everything by 100 or 1000 and you can reduce the size of the numbers in a relevant manor.

160,000 / 1000 = 160 160 would be your denominator. So than 50% would be 80/160. Does this make sense?

Frank V
I think you should reconsider the top formula, while I think I know what you mean, it is in no way clear. And as it stands arguably incorrect.
TommyA
I understand that to turn "1" in to "100", I'd need to multiply it by 100, however mathematically, I believe I'm right when I say `1=100%`.
Frank V
You are correct that 160,000 is equal to a 100% in the described case. So the top formula is arguably correct, however that was not the one I was referring to. The second line formula is more confusing than it is helpful. I would suggest writing `80,000/160,000`=`0.5`=`50%` to keep in line with the top formula.
TommyA
Thank you for the feedback. I've made the change. I guess I was thinking that after the first line, one could skip the middle step but for clarity, I see how illustrating it can help. Again, thanks.
Frank V
@Frank: I think your example is more confusing than it is helpful.
Mark
+5  A: 

Percentage calculation is basic mathematics:

$total = 160000;
$current = 12345;
$percentage = $current/$total * 100;
Gumbo
A: 

Do it Microsoft style:

current = 12345
percentage = 100*(1-exp(-current/100000))
That's bizarre. You shouldn't need to do that.
staticsan