需要帮助NSDecimalNumber

时间:2011-09-12 06:22:04

标签: iphone objective-c cocoa-touch 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];

在乘法线处崩溃,错误为:*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell decimalNumberByMultiplyingBy:]: unrecognized selector sent to instance 0x5d91a60'

2 个答案:

答案 0 :(得分:2)

尝试:

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

答案 1 :(得分:2)

尾数需要是一个整数,所以要乘以十来调整,然后将指数减一。

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