I must be doing something really obviously wrong, but I can't see it.
NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type. It defines a set of methods specifically for setting and accessing the value as a signed or unsigned char , short int , int , long int , long long int , float , or double or as a BOOL .
Converting from double to int. As I mentioned, C++ converts int s to double s automatically if necessary, because no information is lost in the translation. On the other hand, going from a double to an int requires rounding off.
To convert a Double value to an integer value, use the Convert. ToInt32() method. Int32 represents a 32-bit signed integer.
A double is a C type, not an Objective-C object. Hence you use C casts:
double myDouble = 3.2; int myInt = (int)myDouble;
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