开发者

Need Help With NSDecimalNumber

开发者 https://www.devze.com 2023-04-04 17:30 出处:网络
I\'m trying to take an NSDecimalNumber I have, and multiply it by 1.1. I have this but it doesn\'t work:

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:even开发者_开发百科t.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'


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];


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号