frenchie
frenchie

Reputation: 52047

javascript rounding

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.

Upvotes: 0

Views: 175

Answers (5)

Skyste
Skyste

Reputation: 66

rather than Math.round you want Math.ceil

So you'd want

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

Hope that helps!

Upvotes: 1

Ethan Zhang
Ethan Zhang

Reputation: 4479

I think Math.ceil is what you want.

Upvotes: 1

Jonathan Payne
Jonathan Payne

Reputation: 2223

The ceil function rounds up.

Math.ceil( TheCount / 5 );

Upvotes: 5

Alex M
Alex M

Reputation: 3513

Rounding up can be done with Math.ceil

Upvotes: 1

Oleg V. Volkov
Oleg V. Volkov

Reputation: 22481

Use Math.ceil.

Upvotes: 2

Related Questions