Search code examples
iosobjective-cnsnumberformatter

Incorrect behavior of NSNumberFormatter for iOS 8


The below code outputs the correct value till iOS 7

    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"0.000%;0.000%;-0.000%"];
    NSString *str = [numberFormatter stringFromNumber:@0.55368]; 

It outputs str as 55.368%

But in iOS 8 it outputs str as 1.

I don't see any deprecation or any API change in Apple's documentation of NSNumberFormatter. Is it a serious bug or am I missing something here?


Solution

  • This works on iOS7 & iOS8:

    numberFormatter.numberStyle = NSNumberFormatterPercentStyle;
    numberFormatter.minimumFractionDigits = 3;