//这里参数是字符串,可以改成double、float、integer
-(NSString*)notRounding:(NSString*)price afterPoint:(int)position{
NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:position raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
NSDecimalNumber*ouncesDecimal;
NSDecimalNumber*roundedOunces;
ouncesDecimal = [[NSDecimalNumber alloc] initWithString:price];
roundedOunces = [ouncesDecimaldecimalNumberByRoundingAccordingToBehavior:roundingBehavior];
return [NSString stringWithFormat:@"%@",roundedOunces];
}
网友评论