I’m having issues with this when the numbers are large. For example if the number is 3670000000, I want the label to be 3,670,000,000. When the numbers are large it gives me a value of 2,147,483,657. I’m sure it must be a variable length issue. I tried using long long int for numC. Any suggestions would be greatly appreciated. Thanks.
int numC;
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *valuestring= [NSString stringWithFormat:@"%@", [[values objectAtIndex:indexA] objectForKey:@"hits"]];
numC=[valuestring intValue];
NSString *results = [formatter stringFromNumber:[NSNumber numberWithInteger:numC]];
label1.text =results;
The
inttype cannot hold a value greater than 2,147,483,657. You could use an unsigned int and the maximum value would be 4,294,967,295. Look here for more information. You could try this too to extend the range of the data type:Additionally, if none of the values you are retrieving contain a negative value, you could make it an
unsigned long long int. In that case, make your code this:Also make sure that in this line…
…the value you are retrieving is a
long long int.Hope this helps!