Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round an float value and convert it into NSInteger value in the iPhone SDK?

Tags:

objective-c

I need to round a float value and convert it into an NSInteger value.

For example:

float f = 90.909088;

I want the result to be 91. How to get rid of this?

like image 948
monish Avatar asked May 19 '10 11:05

monish


1 Answers

A quick round and cast will work for negative values as well as positives:

NSInteger intValue = (NSInteger) roundf(f);
like image 197
Skurfur Avatar answered Sep 28 '22 16:09

Skurfur