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, and 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With