ios - Converting float to NSNumber -
i missing basic, here. must have forgotten it. basically, have following code purpose take nsnumber, convert float, multiply 2 , return result nsnumber. error on last step, , stumped. should there.
nsnumber *testnsnumber = [[[nsnumber alloc] initwithfloat:200.0f] autorelease]; float myfloatvalue = [testnsnumber floatvalue] * -2; nslog(@" test float value %1.2f \n\n",myfloatvalue); [testnsnumber floatvalue:myfloatvalue]; // error here floatvalue not found
the method floatvalue
of nsnumber
not take parameters. if set new float number, need re-assign testnsnumber
, because nsnumber
not have mutable counterpart:
testnsnumber = @(myfloatvalue); // new syntax
or
testnsnumber = [nsnumber numberwithfloat: myfloatvalue]; // old syntax
Comments
Post a Comment