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];
精彩评论