Дипак ответ, вероятно, именно то, что вам нужно, но я просто предоставляю другой вариант ради вариантов. Я предполагаю, что вы используете NSNumber
значения, поэтому someNumber
будет такого типа в примере:
NSString *numberString = [NSString stringWithFormat:@"%.2f", [someNumber floatValue]];
// this converts the NSNumber to a float, then formats the float in a string;
NSNumber *formattedNumber = [NSNumber numberWithFloat:[numberString floatValue]];
// this extracts the float from the string and puts it back as an NSNumber