需要 NSDecimalNumber 帮助
我正在尝试获取我拥有的 NSDecimalNumber,并将其乘以 1.1。
我有这个,但它不起作用:
NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:1.1 exponent:0 isNegative:NO];
NSDecimalNumber *savings = [totalExpenses decimalNumberByMultiplyingBy:multipy];
更新:
这是完整的代码,有人知道为什么它不起作用吗?
NSDecimalNumber *totalExpenses = [[event.housePayment decimalNumberByAdding:event.carPayment] decimalNumberByAdding:event.loanPayment];
NSDecimalNumber *multiply = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:NO];
NSDecimalNumber *savings = [totalExpenses decimalNumberByMultiplyingBy:multiply];
在乘法行崩溃,错误:*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UITableViewCell DecimalNumberByMultiplyingBy:]:无法识别的选择器发送到实例 0x5d91a60”
I'm trying to take an NSDecimalNumber I have, and multiply it by 1.1.
I have this but it doesn't work:
NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:1.1 exponent:0 isNegative:NO];
NSDecimalNumber *savings = [totalExpenses decimalNumberByMultiplyingBy:multipy];
Update:
Here is the whole code, does anyone know why it doesn't work?
NSDecimalNumber *totalExpenses = [[event.housePayment decimalNumberByAdding:event.carPayment] decimalNumberByAdding:event.loanPayment];
NSDecimalNumber *multiply = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:NO];
NSDecimalNumber *savings = [totalExpenses decimalNumberByMultiplyingBy:multiply];
Crashes at multiplication line, with error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell decimalNumberByMultiplyingBy:]: unrecognized selector sent to instance 0x5d91a60'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尾数必须是整数,因此可以通过乘以十然后将指数减一来进行调整。
IE
Mantissa needs to be an integer, so adjust for this by multiplying by ten and then reducing your exponent by one.
i.e.
尝试:
Try: