How to convert a string into double and vice versa?

You can convert an NSString into a double with

double myDouble = [myString doubleValue];

Rounding to the nearest int can then be done as

int myInt = (int)(myDouble + (myDouble>0 ? 0.5 : -0.5))

I’m honestly not sure if there’s a more streamlined way to convert back into a string than

NSString* myNewString = [NSString stringWithFormat:@"%d", myInt];

Leave a Comment