iOS小数取整的方法(ceil、floor和round)

ceil(value):求大于小数value的最小整数。
floor(value):求小于小数value的最大整数。
round(value):小数value的四舍五入取整。

示例(一):
CGFloat width = 70.15;
[self logCeilFoorRoundWithValue:width];

     打印:
     ceil(a) = 71.000000
     floor(a) = 70.000000
     round(a) = 70.000000

示例(二):
width = 70.77;
[self logCeilFoorRoundWithValue:width];

     打印:
     ceil(a) = 71.000000
     floor(a) = 70.000000
     round(a) = 71.000000
- (void)logCeilFoorRoundWithValue:(CGFloat)value {
    NSLog(@"ceil(a) = %f", ceil(value));
    NSLog(@"floor(a) = %f", floor(value));
    NSLog(@"round(a) = %f", round(value));
}

你可能感兴趣的:(iOS小数取整的方法(ceil、floor和round))