I would like to make one of my UILabels show a maximum of 3 digits. So, if the associated value is 3.224789, I would like to see 3.22. If the value is 12.563, I would like to see 12.5, and if the value is 298.38912, then I would like to see 298. I tried to use NSNumberFormatter for this, but when I set the maximum significant digits to 3 it always has 3 digits after the decimal place. Here is the code:
NSNumberFormatter *distanceFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [distanceFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; [distanceFormatter setAlwaysShowsDecimalSeparator:NO]; [distanceFormatter setMaximumSignificantDigits:3];
I always thought that “significant digits” means all digits before and after the decimal point. Anyway, is there a way to accomplish this using NSNumberFormatter?
Thanks!
source share