Convert NSString to double for calculations and then back again to print in NSString

Omkar Jadhav picture Omkar Jadhav · Jul 21, 2010 · Viewed 24.5k times · Source

I accept NSString as

NSString *value = [valuelist objectAtIndex:valuerow];
NSString *value2 = [valuelist2 objectAtIndex:valuerow2];

from UIPickerView. I want to

double *cal = value + (value2 * 8) + 3;


NSString *message =[[NSString alloc] initWithFormat:@"%@",cal];

I should be able to get the string in message after I do the calculations on it .. Please help My program is crashing

Answer

Joshua Weinberg picture Joshua Weinberg · Jul 21, 2010
double cal = [value doubleValue] + ([value2 doubleValue] * 8) + 3;
NSString *message =[[NSString alloc] initWithFormat:@"%f",cal];