If the double exceeds 15 digits including decimals, it should turn over to scientific notation with 6 digits of precision.
Do you mean always 6 fractional digits but if the integer part exceeds 9 digits, then go to scientific notation? If so, then here's my solution.
NSString *numberToString(NSNumber *number) {
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
// If number has (15 - 6) or less integer digits
if ([number integerValue] < 1E9) {
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setUsesGroupingSeparator:YES];
} else {
[formatter setNumberStyle:NSNumberFormatterScientificStyle];
}
[formatter setMinimumFractionDigits:6];
[formatter setMaximumFractionDigits:6];
return [formatter stringFromNumber:number];
}