There's no text in the documentation about what that means, but it sounds very important to understand in order to not run into trouble. Does someone know what that is all about the "significant digits" of a number?
Objective-c – What describes NSNumberFormatter -maximumSignificantDigits
cocoa-touchfoundationiphoneobjective cuikit
Related Topic
- Objective-c – a typedef enum in Objective-C
- Ios – How to draw a shadow under a UIView
- Ios – How to make a UITextField move up when the keyboard is present – on starting to edit
- Objective-c – @synthesize vs @dynamic, what are the differences
- Ios – Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets
- Ios – Why does viewWillAppear not get called when an app comes back from the background
- Ios – How to find topmost view controller on iOS
- Java – the best approach for having some kind of lazy iterator where the return is evaluated only on request
Best Answer
Although the other answer on this question links to a correct explanation of the concept of significant digits in general,
NSNumberFormatter
's{uses|minimum|maximum}SignificantDigits
properties have nothing to do with precision of calculations.The significant digits are the group of digits in a number from the first nonzero digit to the last nonzero digit, inclusive, usually unless trailing zeroes are fractional. Restricting output to a specific number of significant digits is useful if a relative (percentage) error is known or desired.
First of all, the
minimumSignificantDigits
andmaximumSignificantDigits
have no effect unlessusesSignificantDigits
is set toYES
. If this is the case, their effect is probably most easily explained using examples.Let's take the numbers
a = 123.4567
,b = 1.23
, andc = 0.00123
:Assuming
minimumSignificantDigits = 0
,1
or2
:If
maximumSignificantDigits = 3
, thena
will be formatted as "123",b
as "1.23", andc
as "0.00123".If
maximumSignificantDigits = 4
, thena
will be formatted as "123.5",b
as "1.23" andc
as "0.00123".If
maximumSignificantDigits = 2
, thena
will be formatted as "120",b
as "1.2" andc
as "0.0012".Assuming
minimumSignificantDigits = 4
:If
maximumSignificantDigits = 4
, thena
will be formatted as "123.5",b
as "1.230", andc
as "0.001230".Note: The 4 → 5 conversions occur due to the round-to-nearest mode, as the digit following the 4 in a is 5.