Assign the value from a text field into an int variable to do some math with other variables and then return it?

39 views Asked by At

The code showing here assigns the value of an variables to the text field I want to do the opposite of that. _Initial.text = [NSString stringWithFormat:@"%f", init];

The opposite of the code above. Please help

2

There are 2 answers

0
Claudio Redi On BEST ANSWER

The opposite of that would be getting converting string to float. You can do it with this

init = [_Initial.text floatValue];
1
dave234 On

You should search for an answer before you ask a question.

NSString *intString = @"123";
NSString *floatString = @"456.789";
int intVal = [intString intValue];
float floatVal = [floatString floatValue];
printf("%i %f\n",intVal,floatVal);