Search code examples
objective-cnsnumberformatter

Why does NSNumberFormatter skip a number?


So lets say I have the following:

NSNumber *num = [NSNumber numberWithDouble:12345678901234567];

Now I would like for that to be formatted as a string in the following format: 1.234567E16

I have tried both:

    formatter.numberStyle = NSNumberFormatterScientificStyle;
    formatter.maximumFractionDigits = 6;

and

formatter.positiveFormat = @"0.00000E0";

But my result is always 1.23457E16

Why does it skip the 6?

If I change it to maximumFractionDigits = 7 it would print 1.234568E16

What am I doing wrong?


Solution

  • It's most likely rounding the 6 up to 7.