保留小数
1 //保留两位小数 2 +(NSString *)roundUp:(float)number afterPoint:(int)position 3 { 4 NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundUp scale:position raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO]; 5 NSDecimalNumber *ouncesDecimal; 6 NSDecimalNumber *roundedOunces; 7 8 ouncesDecimal = [[NSDecimalNumber alloc] initWithFloat:number]; 9 roundedOunces = [ouncesDecimal decimalNumberByRoundingAccordingToBehavior:roundingBehavior]; 10 return [NSString stringWithFormat:@"%@",roundedOunces]; 11 }
我的心愿是什么呢