I know you can sum an array of NSNumbers by using the @sum.self keypath, but does that also work with NSDecimalNumbers? Will the result be accurate?
EDIT: To be more specific, here is code I know that works with NSNumber.
NSNumber *sum = [numArray valueForKeyPath:@"@sum.self"];
NSDecimalNumber
is a subclass of NSNumber
, so it will inherit this ability.
Also, I would recommend using one of these:
NSDecimalNumber *sum = [numArray valueForKeyPath:@"@sum.floatValue"];
float sum = [[numArray valueforKeyPath:@"@sum.floatValue"] floatValue];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With