0

I want to round TheCount / 5 to the next highest integer. When TheCount = 12

I tried:

Math.round(TheCount / 5); 

but it returns 2 and I need it to return 3.

How does rounding to the next highest integer work?

Thanks.

3
  • What type of rounding are you trying to perform? 12 / 5 = 2.4, and most people would say that round(2.4) = 2 is correct. Commented Apr 28, 2012 at 12:00
  • @PhilipSheard: I'm using this to count the number of pages. So 12 items with 5 items per pages is 3 pages. Commented Apr 28, 2012 at 12:02
  • Then in plain English you are rounding up, not rounding. You want the ceil function, as everyone suggests. Commented Apr 28, 2012 at 12:04

5 Answers 5

5

The ceil function rounds up.

Math.ceil( TheCount / 5 ); 
Sign up to request clarification or add additional context in comments.

Comments

2

Use Math.ceil.

Comments

1

Rounding up can be done with Math.ceil

Comments

1

I think Math.ceil is what you want.

Comments

1

rather than Math.round you want Math.ceil

So you'd want

var result = Math.ceil(TheCount / 5);

Hope that helps!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.