2
 perc = 15/30;
 //result=Math.round(perc*100)/100  //returns 28.45
 $('#counter').text(perc);
 $('#total').text(count);

returns back 0.5% which is suppose to be 50.00%... how do I fix this? :S

5
  • 40
    Multiply by 100. I'm not going to post this as an answer, because this is too… strange. Commented Sep 9, 2010 at 16:49
  • 1
    @Tomalak Because those low rep users have to get their reps from somewhere :) Commented Sep 9, 2010 at 16:51
  • 15
    How can ((15/30)*100)/100 return 28.45? Commented Sep 9, 2010 at 16:52
  • 3
    @Álvaro: It doesn't, that's why it is commented out. :-D Commented Sep 9, 2010 at 16:59
  • 15/30 is a fraction, not a percentage. Commented Sep 12, 2010 at 23:41

4 Answers 4

48

You do realize that word percent quite literally translates into "per cent" or "per 100" since cent is the latin root that's used everywhere meaning "100" or "one-hundredth".

  • Century (100 years)
  • US Cent (100th of a dollar)
  • Centurion (Those who commanded 100 soldiers)
  • Centipede (creature with 100 legs)

So 50% becomes 50 per cent becomes 50 per 100

And, since in mathematical terms, the word per means divide (miles per hour == mph == m/h) then we can distill 50% down to:

50/100

Which, surprisingly enough, is represented as the decimal number .5

Sign up to request clarification or add additional context in comments.

Comments

11

15/30 = 0.5

if you want to have percent number you have to multiply it by 100.

Comments

7

I am a low rep user so here goes. http://en.wikipedia.org/wiki/Percentage

Treat the % sign as a constant equal to 0.01. Thus, when working with a number like 50%, treat it as 50 * 0.01 or 0.5.

0.5 = n %                  // I want to know what 0.5 is as a percent
0.5 / % = n * % / %        // Divide both sides by the constant
0.5 / % = n                // Remove the excess
0.5 / 0.01 = n             // Replace the constant
50 = n                     // You have your answer

Comments

5

Just multiply by 100.

1 Comment

i like this answer... it's so simple and straight forward :p

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.