I've tried looking around and can't seem to find anything to something that I thought should be fairly simple to implement. Basically I just want to find a way to take a list of numbers and shorten them down to an abbreviated format (for example 1000 to 1k and 500000 to 500k). I tried using this below, and it's working so far but I feel like I'm just going to have to cycle through every possible format so I'm wondering if there was something simpler to do this or if I just need to use this method.
-(NSString *)formatStringFromNumber:(int)num {
NSString *value = nil;
if (num >= 100000) {
value = [NSString stringWithFormat:@"$%dk", (num/1000)];
}
if (num >= 10000) {
value = [NSString stringWithFormat:@"$%dk", (num/1000)];
}
if (num >= 100000000) {
value = [NSString stringWithFormat:@"$%dM", (num/1000000)];
}
return value;
}