2011-09-12 44 views
0

我試圖把我有的NSDecimalNumber乘以1.1。需要NSDecimalNumber的幫助

我有這個,但它不工作:

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'

+0

你得到了什麼消息,當它崩潰? –

+0

我剛發佈了消息 – Jon

+0

什麼是'event.housePayment' - 你確定它是一個'NSDecimalNumber'嗎?您還沒有向我們展示過其他代碼行嗎? –

回答

2

尾數必須是一個整數,所以通過十相乘,然後通過減少指數調整這一。

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

嘗試:

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