Hi Guys,
I need to round a float value and convert it into NSInteger value.
for example:
float f = 90.909088;
I want the result as 91.
Can any one help to get rid of this.
Anyone's help will be much appreciated.
Hi Guys,
I need to round a float value and convert it into NSInteger value.
for example:
float f = 90.909088;
I want the result as 91.
Can any one help to get rid of this.
Anyone's help will be much appreciated.
Try:
float f = 90.909088;
NSNumber *myNumber = [NSNumber numberWithDouble:(f+0.5)];
NSInteger myInt = [myNumber intValue];
One of the following C math functions might work for you:
To get more documentation, open a terminal session and type (for example)
man lround
I pick lround as an example because I think that is the one you want.