As your NSLog() output shows, self.userData.RawPercentage
and self.userData.FixedPrice
are nil
, i.e. are not allocated + initialized as NSDecimalNumber
objects.
nil
cannot be used to represent the decimal number zero!
In fact, when I try your code,
NSDecimalNumber *custPrice1 = [oneWithNet decimalNumberByAdding:priceFixed];
crashes because priceFixed
is nil.
So you should check the code where these variables are initialized and make sure that they point to valid NSDecimalNumber
objects.
UPDATE: The error message
-[__NSCFNumber decimalNumberByMultiplyingBy:]: unrecognized selector sent to instance 0x84ad160
shows that nettoPrijs
is a NSNumber
object and not a NSDecimalNumber
. The following simplified code shows what happens if you try to multiply a NSDecimalNumber
with a NSNumber
:
NSDecimalNumber *one = [NSDecimalNumber one];
id price = [NSNumber numberWithFloat:89.25];
NSDecimalNumber *product = [one decimalNumberByMultiplyingBy:price];
NSLog(@"product = %@", product);
// Output:
// product = -0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000221166721562906606351581184
(I have no idea why this doesn't crash or produce some error message.)
It works correctly if you multiply with a NSDecimalNumber
:
price = [NSDecimalNumber decimalNumberWithString:@"89.25"];
product = [one decimalNumberByMultiplyingBy:price];
NSLog(@"product = %@", product);
// Output:
// product = 89.25
So I assume that self.netPrice
is a NSNumber
object which has to be converted to a NSDecimalNumber
. The same may apply to the other number objects.