#pragma mark - 四舍五入 例如:5.25输出5 5.55输出6
- (NSString *)floatRounded:(float)a withCount:(NSInteger)count{
float val = powf(10,count);
CGFloat roundA = roundf(a * val);
NSMutableString *result=[NSMutableString stringWithFormat:@"%lf",roundA];
[result insertString:@"." atIndex:count];
return result;
}
#pragma mark - 进位 例如:5.25和5.55都输出6
- (NSString *)floatRounded:(float)a withCount:(NSInteger)count{
float val = powf(10,count);
CGFloat roundA = ceilf(a * val);
NSMutableString *result=[NSMutableString stringWithFormat:@"%lf",roundA];
[result insertString:@"." atIndex:count];
return result;
}
#pragma mark - 抹位 例如:5.25和5.55都输出5
- (NSString *)floatRounded:(float)a withCount:(NSInteger)count{
float val = powf(10,count);
CGFloat roundA = roundf(a * val);
NSMutableString *result=[NSMutableString stringWithFormat:@"%lf",roundA];
[result insertString:@"." atIndex:count];
return result;
}
floatnumberToRound;intresult; numberToRound = 5.61; result = (int)ceilf(numberToRound);NSLog(@"ceilf(%.2f) = %d", numberToRound, result);//输出 ceilf(5.61) = 6numberToRound = 5.41; result = (int)ceilf(numberToRound);NSLog(@"ceilf(%.2f) = %d", numberToRound, result);//输出 ceilf(5.41) = 6