0
我有數量字符串值,如1000,100000,1000000000,5000。問題是我正在使用排序描述符進行排序。它的排序正確的字符串明智的,但轉換爲1K,10K,1M後,5K它不工作,請讓我知道你的建議iphone +如何排序數量字符串
這裏是我的源代碼
[m_sortTempArray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSDictionary *dict1 = obj1;
NSDictionary *dict2 = obj2;
NSString *string1 = nil;
NSString *string2 = nil;
if (1)
{
if ([[dict1 objectForKey:@"kpiData"] count]>0 && [[dict2 objectForKey:@"kpiData"] count]>0) {
string1 = [[[dict1 objectForKey:@"kpiData"] objectAtIndex:kIndex] objectForKey:@"kpiActual"];
string2 = [[[dict2 objectForKey:@"kpiData"] objectAtIndex:kIndex] objectForKey:@"kpiActual"];
} else {
//return 0;
[email protected]"0";
[email protected]"0";
}
}
if ([string2 isEqualToString:@""]){
string2 = @"0";
}
if ([string1 isEqualToString:@""]){
string1 = @"0";
}
if ([string1 integerValue] > [string2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
if ([string1 integerValue] < [string2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}
return (NSComparisonResult)NSOrderedSame;
}];