I'm trying to use NSNumberFormatter
to round a number to 5 decimal places in an iPhone app, but [formatter stringFromNumber:]
always returns strings rounded to 0.001 (3 decimal places). What am I doing wrong?
formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setRoundingMode:NSNumberFormatterRoundHalfUp];
[formatter setSecondaryGroupingSize:3];
[formatter setRoundingIncrement:[NSNumber numberWithDouble:0.00001]];
See Question&Answers more detail:os