Total newbie question but this is driving me mad! I try myInt = [myFloat integerValue]; and I get an error saying essentially integerValue doesn't work on floats. How do I do it?
+5
A:
what's wrong with:
int myInt = myFloat;
bear in mind this'll use the default rounding rule, which is towards zero (i.e. -3.9f becomes -3)
Alnitak
2008-11-13 10:32:52
+10
A:
I'm pretty sure C-style casting syntax works in Objective C, so try that, too:
int myInt = (int) myFloat;
It might silence a compiler warning, at least.
unwind
2008-11-13 10:38:43
A:
In support of unwind, remember that Objective-C is a superset of C, rather than a completely new language.
Anything you can do in regular old ANSI C can be done in Objective-C.
Matthew Schinckel
2008-11-13 21:48:19