I've been searching for quite awhile and can't seem to find anything on this. How do I round a number up to the nearest whole number? I'm using the number of objects in an array and dividing it by 3. Say [array count] is 10, and I want to get a 4 as the result of 10/3. Or [array count] is 23, an开发者_如何学God I want to get an 8. How do I do this? Thanks in advance.
Be sure to cast the number you're rounding:
int roundedNumber = ceil((double)number/3);
Otherwise integer arithmetic will truncate.
ceil() function is what you are looking for.
精彩评论