Я должен понять это. Вы можете сделать это согласно приведенной ниже реализации.
Пожалуйста, посмотрите демонстрационный код ниже ...
NSArray * numbers = [[NSArray alloc] initWithObjects:@"1.1500",@"1.1000",@"1.0000",@"1.4710",@"1.4711",nil];
for (int i=0; i<[numbers count]; i++) {
NSArray * floatingPoint = [[numbers objectAtIndex:i] componentsSeparatedByString:@"."];
NSString * lastObject = [[floatingPoint lastObject] stringByReplacingOccurrencesOfString:@"0" withString:@""];
if ([lastObject length] < 2) {
NSLog(@"%@",[NSString stringWithFormat:@"$ %.2f",[[numbers objectAtIndex:i] floatValue]]);
} else {
NSLog(@"%@",[NSString stringWithFormat:@"$ %g",[[numbers objectAtIndex:i] floatValue]]);
}
}
Спасибо
MinuMaster