oc的double,float类型无法满足小数乘法的需求
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #00afca }
span.s1 { }
只能用NSDecimalNumber实现
NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:0 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:YES]; NSDecimalNumber *a = [[NSDecimalNumber alloc]initWithString:@"0.8"]; NSDecimalNumber *b = [[NSDecimalNumber alloc]initWithString:@"0.6"]; //相乘并取整 NSDecimalNumber *c = [a decimalNumberByMultiplyingBy:b withBehavior:roundingBehavior];
时间: 2024-10-06 00:42:39