- (NSString *)calResultToStr:(double)result {
int r_i = ceil(result);
if (!separatorArray) {
separatorArray = [[NSMutableArray alloc]init];
}
[separatorArray removeAllObjects];
while (r_i/1000 > 0) {
NSString *numStr = [[NSString alloc]init];
double temp = r_i%1000;
if (temp > 0) {
NSString *str = [NSString stringWithFormat:@"%d",(int)temp];
if (str.length == 1) {
numStr = [numStr stringByAppendingFormat:@"00%d",(int)temp];
}
else if (str.length == 2) {
numStr = [numStr stringByAppendingFormat:@"0%d",(int)temp];
}
else {
numStr = [numStr stringByAppendingFormat:@"%d",(int)temp];
}
}
else {
numStr = @"000";
}
[separatorArray insertObject:numStr atIndex:0];
r_i = floor(r_i/1000);
}
[separatorArray insertObject:[NSString stringWithFormat:@"%d",r_i] atIndex:0];
return [separatorArray componentsJoinedByString:@","];
}
转载于:https://blog.51cto.com/darkeve/1383826