保留小数

 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 }

 

posted @ 2017-03-21 09:47  福泽小院  阅读(150)  评论(0编辑  收藏  举报