标签:deb ber string bsp eal val ima 处理 blog
- (NSString *)getDealNumwithstring:(NSString *)string withNumCount:(NSInteger)integer{ NSDecimalNumber *numberA = [NSDecimalNumber decimalNumberWithString:string]; NSDecimalNumber *numberB ; if (integer == 4) { numberB = [NSDecimalNumber decimalNumberWithString:@"10000"]; } else if (integer == 8){ numberB = [NSDecimalNumber decimalNumberWithString:@"100000000"]; }else{ numberB = [NSDecimalNumber decimalNumberWithString:@"10000"]; } //NSDecimalNumberBehaviors对象的创建 参数 1.RoundingMode 一个取舍枚举值 2.scale 处理范围 3.raiseOnExactness 精确出现异常是否抛出原因 4.raiseOnOverflow 上溢出是否抛出原因 4.raiseOnUnderflow 下溢出是否抛出原因 5.raiseOnDivideByZero 除以0是否抛出原因。 NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO]; /// 这里不仅包含Multiply还有加 减 乘。 NSDecimalNumber *numResult = [numberA decimalNumberByDividingBy:numberB withBehavior:roundingBehavior]; NSString *strResult = [numResult stringValue]; return strResult; }
标签:deb ber string bsp eal val ima 处理 blog
原文地址:http://www.cnblogs.com/weipeng168/p/7112252.html