Contents

NumberFormatter

A formatter that converts between numeric values and their textual representations.

Declaration

class NumberFormatter

Overview

Instances of NumberFormatter format the textual representation of cells that contain NSNumber objects and convert textual representations of numeric values into NSNumber objects. The representation encompasses integers, floats, and doubles; floats and doubles can be formatted to a specified decimal position. NumberFormatter objects can also impose ranges on the numeric values cells can accept.

Significant Digits and Fraction Digits

The NumberFormatter class provides flexible options for displaying non-zero fractional parts of numbers.

If you set the usesSignificantDigits property to true, you can configure NumberFormatter to display significant digits using the minimumSignificantDigits and maximumSignificantDigits properties. If usesSignificantDigits is false, these properties are ignored. See Configuring Significant Digits.

Otherwise, you can configure the minimum and maximum number of integer and fraction digits, or the numbers before and after the decimal separator, respectively, using the minimumIntegerDigits, maximumIntegerDigits, minimumFractionDigits, and maximumFractionDigits properties. See Configuring Integer and Fraction Digits.

Thread Safety

On iOS 7 and later NumberFormatter is thread-safe.

In macOS 10.9 and later NumberFormatter is thread-safe so long as you are using the modern behavior in a 64-bit app.

On earlier versions of the operating system, or when using the legacy formatter behavior or running in 32-bit in macOS, NumberFormatter is not thread-safe, and you therefore must not mutate a number formatter simultaneously from multiple threads.

Topics

Configuring Formatter Behavior and Style

Converting Between Numbers and Strings

Managing Localization of Numbers

Configuring Rounding Behavior

Configuring Integer and Fraction Digits

Configuring Significant Digits

Configuring Numeric Formats

Configuring Numeric Symbols

Configuring the Format of Currency

Configuring Numeric Prefixes and Suffixes

Configuring the Display of Numeric Values

Configuring Separators and Grouping Size

Managing the Padding of Numbers

Managing Input and Output Attributes

Managing Leniency Behavior

Managing the Validation of Partial Numeric Strings

Constants

Instance Properties