0

I have an entity attribute in which are stored both numbers and empty field. I need the sum and the average values of this attributes values but doing @"@sum.attributeName" or @"@avg.attributeName" I get

Terminating app due to uncaught exception 'NSDecimalNumberOverflowException', reason: 'NSDecimalNumber overflow exception'

Thank's

Alain
  • 105
  • 7
  • What data type is your attributeName? It sounds like it's string data type. – Greg Dec 24 '13 at 17:13
  • Your code is trying to get sum/average of string. It doesn't work because it works just on numeric values. – Greg Dec 24 '13 at 19:24
  • I can confirm that even if it is NSString it works until there are only numbers... The problem starts when there are empty values. Is there a way to not include the empty values in the @avg or @sum? – Alain Dec 25 '13 at 01:02
  • see [here](http://stackoverflow.com/questions/17574782/core-data-how-to-display-results-of-a-fetchrequest-for-calculating-values-in-a/17607207#17607207) – Dan Shelly Dec 25 '13 at 07:05

1 Answers1

0

I solved even if the Attributes are String Type as follows:

 NSArray *allValues = [array valueForKeyPath:@"@unionOfObjects.entityAttribute"];
NSMutableArray *allNumberValues = [[NSMutableArray alloc] init];


for (int i=0; i<valoriVotoEsame.count; i++) {

    if (            ![[allValues objectAtIndex:i] isEqual:@""])
    {
        [allNumberValues addObject:[allValues objectAtIndex:i]];


    }

}
Alain
  • 105
  • 7