tags:

views:

208

answers:

2

How does one convert an unsigned long number to a float in Objective-C?

+2  A: 

Objective-C is remarkably similar to C. In fact, it can be implemented as a layer on top of standard C with runtime support for the creation and destruction of objects.

What that generally means is that most things you can do in C, you can also do in Objective-C. Casting an unsigned long to a float is done (in both languages) as follows.

unsigned long ul = 7;
float f = (float)ul;
paxdiablo
+1  A: 

Typecast it the same as in C. Typecasting is explicitly converting one data type to another.

unsigned long myLong = 5;
float myFloat = (float)myLong;

(float)myFloat is the key. The datatype (i.e. float, int) goes in the parentheses and directly after it comes the variable you're typecasting.

http://docs.hp.com/en/B3901-90007/ch05s05.html has further information.

Walker Argendeli
Thank you very much!
Eric Christensen