Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounded up float value ios

Tags:

objective-c

I Have a value for example int value1 = 11 after dividing on 2 (value1 / 2) its returning 5. Real value in float is 5.5, can anybody help me to return 6 in this case, or another case..? In general, I want to round the value to the next higher..

like image 944
LightNight Avatar asked Nov 28 '22 01:11

LightNight


1 Answers

If you always want to round up, and you have a float value, use ceilf (from the <math.h> library).

If you want to round up an integer division by n, do (value + n-1) / n. So, for a division by 2, this becomes (value + 1) / 2.

like image 157
nneonneo Avatar answered Jan 11 '23 23:01

nneonneo