[ACCEPTED]-Objective-C, how do I convert a double to an int?-xcode

Accepted answer
Score: 91

A double is a C type, not an Objective-C 1 object. Hence you use C casts:

double myDouble = 3.2;
int myInt = (int)myDouble;
Score: 4

Just converting mentioned above is good 2 enough though you might want to use floor() or 1 ceil() functions before that.

Score: 1

intValue is a method for a NSNumber instance. For scale 5 type like int, double, and float, they are 4 not class type. So, they have no methods. Some 3 languages like C# may wrap int, or double 2 as a object, and they can be transfered 1 to each other by a sub-routine.

Score: 1

try this

NSInteger number=33;
NSUInteger count = (NSInteger)[number];

here, NSUInteger is long. number is NSInteger


More Related questions