How can I divide two NSIntegers, for instance, 13 / 4 and round the result to the next integer = 3?
I have seen some samples converting the integers to float and back to integer. But what is the recommended way with the least amount of code to do it?
Assuming x >= 0
and y > 0
:
If you want to round down: x / y
If you want to round up: (x + y - 1) / y
If you want to round to nearest: (x + y / 2) / y
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