需要 NSDecimalNumber 帮助

发布于 2024-12-04 00:03:12 字数 821 浏览 4 评论 0原文

我正在尝试获取我拥有的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如此安好 2024-12-11 00:03:12

尾数必须是整数,因此可以通过乘以十然后将指数减一来进行调整。

IE

NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:NO];

Mantissa needs to be an integer, so adjust for this by multiplying by ten and then reducing your exponent by one.

i.e.

NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:NO];
╰◇生如夏花灿烂 2024-12-11 00:03:12

尝试:

NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:YES]; 

Try:

NSDecimalNumber *multipy = [NSDecimalNumber decimalNumberWithMantissa:11 exponent:-1 isNegative:YES]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文