Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C, how do I convert a double to an int?

I must be doing something really obviously wrong, but I can't see it.

alt text

like image 315
Jules Avatar asked Oct 30 '10 10:10

Jules


People also ask

What is NSNumber in Objective C?

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 .

Can double be converted to int in C++?

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.

Can you convert double to in C#?

To convert a Double value to an integer value, use the Convert. ToInt32() method. Int32 represents a 32-bit signed integer.


1 Answers

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

double myDouble = 3.2; int myInt = (int)myDouble; 
like image 166
Georg Schölly Avatar answered Sep 29 '22 02:09

Georg Schölly