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
2009-06-24 05:33:28
+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
2009-06-24 05:34:07
Thank you very much!
Eric Christensen
2009-06-24 05:42:21