/**
四舍五入字符串
@param round 小数位 eg: 2
@param numberString 数字 eg 0.125
@return 四舍五入之后的 eg: 0.13
*/
-
(double )roundNumberStringWithRound:(NSInteger)round numberString:(NSString *)numberString{
if (numberString == nil) {
return 0;
}
NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:round raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
NSDecimalNumber *aDN = [[NSDecimalNumber alloc] initWithString:numberString];
NSDecimalNumber *resultDN = [aDN decimalNumberByRoundingAccordingToBehavior:roundingBehavior];
return resultDN.doubleValue;
}
网友评论