NSDecimalNumber用来处理iOS中金额显示问题,可以转换string类型,也可以将int类型转换成Number然后转为NSDecimalNumber
NSDecimalNumber*priceDecimalNum = [NSDecimalNumber decimalNumberWithString:priceStr];
//将数量转为NSDecimal
NSDecimal countDec = [[NSNumber numberWithInteger:model.countNum]decimalValue];
//单价x数量
priceDecimalNum = [priceDecimalNum decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithDecimal:countDec]];
//折扣后总价
totalPrice = [totalPricedecimal NumberByAdding:priceDecimalNum];
//原商品总价
NSDecimalNumber *oriDecimalNum = [NSDecimalNumber decimalNumberWithString:model.productPrice];
oriDecimalNum = [oriDecimalNum decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithDecimal:countDec]];
oriTotalPrice = [oriTotalPrice decimalNumberByAdding:oriDecimalNum];
网友评论