iOS Developer Library

Developer

CoreFoundation Framework Reference CFNumberFormatter Reference

Options
Deployment Target:

On This Page
Language:

CFNumberFormatter Reference

CFNumberFormatter objects format the textual representations of CFNumber objects, and convert textual representations of numbers into CFNumber objects. The representation encompasses integers, floats, and doubles; floats and doubles can be formatted to a specified decimal position. You specify how strings are formatted and parsed by setting a format string and other properties of a CFNumberFormatter object.

The format of the format string is defined by Unicode Technical Standard #35; the version of the standard used varies with release of the operating system, and is described in Introduction to Data Formatting Programming Guide For Cocoa.

Unlike some other Core Foundation opaque types with names similar to a corresponding Cocoa Foundation class (such as CFString and NSString), CFNumberFormatter objects cannot be cast (“toll-free bridged”) to NSNumberFormatter objects.

Functions

  • Creates a new CFNumberFormatter object, localized to the given locale, which will format numbers to the given style.

    Declaration

    Swift

    func CFNumberFormatterCreate(_ alloc: CFAllocator!, _ locale: CFLocale!, _ style: CFNumberFormatterStyle) -> CFNumberFormatter!

    Objective-C

    CFNumberFormatterRef CFNumberFormatterCreate ( CFAllocatorRef allocator, CFLocaleRef locale, CFNumberFormatterStyle style );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    locale

    A locale to use for localization. If NULL, the function uses the default system locale. Use CFLocaleCopyCurrent to specify the locale of the current user.

    style

    A number style. See Number Formatter Styles for possible values.

    Return Value

    A new number formatter, localized to the given locale, which will format numbers using the given style. Returns NULL if there was a problem creating the formatter. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Sets the format string of a number formatter.

    Declaration

    Swift

    func CFNumberFormatterSetFormat(_ formatter: CFNumberFormatter!, _ formatString: CFString!)

    Objective-C

    void CFNumberFormatterSetFormat ( CFNumberFormatterRef formatter, CFStringRef formatString );

    Parameters

    formatter

    The number formatter to modify.

    formatString

    The format string to be used by formatter. See Creating and Using CFNumberFormatter Objects for more information.

    Discussion

    The format string may override other properties previously set using other functions. If this function is not called, the default value of the format string is derived from the number formatter’s style.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Sets a number formatter property using a key-value pair.

    Declaration

    Swift

    func CFNumberFormatterSetProperty(_ formatter: CFNumberFormatter!, _ key: CFString!, _ value: AnyObject!)

    Objective-C

    void CFNumberFormatterSetProperty ( CFNumberFormatterRef formatter, CFStringRef key, CFTypeRef value );

    Parameters

    formatter

    The number formatter to modify.

    key

    The name of the property of formatter to set. See Number Formatter Property Keys for a description of possible values.

    value

    The value of the specified key. This must be an instance of the correct CFType object for the corresponding key.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a number object representing a given string.

    Declaration

    Swift

    func CFNumberFormatterCreateNumberFromString(_ alloc: CFAllocator!, _ formatter: CFNumberFormatter!, _ string: CFString!, _ rangep: UnsafeMutablePointer<CFRange>, _ options: CFOptionFlags) -> CFNumber!

    Objective-C

    CFNumberRef CFNumberFormatterCreateNumberFromString ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFOptionFlags options );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    formatter

    The number formatter to use.

    string

    The string to parse.

    rangep

    A reference to a range that specifies the substring of string to be parsed. If NULL, the whole string is parsed. On return, contains the range of the actual extent of the parse (may be less than the given range).

    options

    Specifies various configuration options to change the behavior of the parse. Currently, kCFNumberFormatterParseIntegersOnly is the only possible value for this parameter.

    Return Value

    A new number that represents the given string. Returns NULL if there was a problem creating the number. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a string representation of the given number using the specified number formatter.

    Declaration

    Swift

    func CFNumberFormatterCreateStringWithNumber(_ alloc: CFAllocator!, _ formatter: CFNumberFormatter!, _ number: CFNumber!) -> CFString!

    Objective-C

    CFStringRef CFNumberFormatterCreateStringWithNumber ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberRef number );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    formatter

    The number formatter to use.

    number

    The number from which to create a string representation.

    Return Value

    A new string that represents the given number in the specified format. Returns NULL if there was a problem creating the string. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a string representation of the given number or value using the specified number formatter.

    Declaration

    Swift

    func CFNumberFormatterCreateStringWithValue(_ alloc: CFAllocator!, _ formatter: CFNumberFormatter!, _ numberType: CFNumberType, _ valuePtr: UnsafePointer<Void>) -> CFString!

    Objective-C

    CFStringRef CFNumberFormatterCreateStringWithValue ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberType numberType, const void *valuePtr );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    formatter

    The number formatter to use.

    numberType

    The type of value that valuePtr references. Valid values are listed in Number Types.

    valuePtr

    A pointer to the value to be converted.

    Return Value

    A new string that represents the given number or value formatted by formatter. Returns NULL if there was a problem creating the object. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the number of fraction digits that should be displayed, and the rounding increment, for a given currency.

    Declaration

    Swift

    func CFNumberFormatterGetDecimalInfoForCurrencyCode(_ currencyCode: CFString!, _ defaultFractionDigits: UnsafeMutablePointer<Int32>, _ roundingIncrement: UnsafeMutablePointer<Double>) -> Boolean

    Objective-C

    Boolean CFNumberFormatterGetDecimalInfoForCurrencyCode ( CFStringRef currencyCode, int32_t *defaultFractionDigits, double *roundingIncrement );

    Parameters

    currencyCode

    A string containing a ISO 4217 3-letter currency code. For example, AUD for Australian Dollars, EUR for Euros.

    defaultFractionDigits

    Upon return, contains the number of fraction digits that should be displayed for the currency specified by currencyCode.

    roundingIncrement

    Upon return, contains the rounding increment for the currency specified by currencyCode, or 0.0 if no rounding is done by the currency.

    Return Value

    true if the information was obtained successfully, otherwise false (for example, if the currency code is unknown or the information is not available).

    Discussion

    The returned values are not localized because these are properties of the currency.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a number or value representing a given string.

    Declaration

    Swift

    func CFNumberFormatterGetValueFromString(_ formatter: CFNumberFormatter!, _ string: CFString!, _ rangep: UnsafeMutablePointer<CFRange>, _ numberType: CFNumberType, _ valuePtr: UnsafeMutablePointer<Void>) -> Boolean

    Objective-C

    Boolean CFNumberFormatterGetValueFromString ( CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFNumberType numberType, void *valuePtr );

    Parameters

    formatter

    The number formatter to use.

    string

    The string to parse.

    rangep

    A reference to a range that specifies the substring of string to be parsed. If NULL, the whole string is parsed. Upon return, contains the range of the actual extent of the parse (may be less than the given range).

    numberType

    The type of value that valuePtr references. Valid values are listed in Number Types.

    valuePtr

    Upon return, contains a number or value representing the string in the specified format. You are responsible for releasing this value.

    Return Value

    true if the string was parsed successfully, otherwise false.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the type identifier for the CFNumberFormatter opaque type.

    Declaration

    Swift

    func CFNumberFormatterGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFNumberFormatterGetTypeID ( void );

    Return Value

    The type identifier for the CFNumberFormatter opaque type.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

Data Types

Miscellaneous

  • Type for constants specifying a formatter style.

    Declaration

    Swift

    enum CFNumberFormatterStyle : CFIndex { case NoStyle case DecimalStyle case CurrencyStyle case PercentStyle case ScientificStyle case SpellOutStyle }

    Objective-C

    typedef CFIndex CFNumberFormatterStyle;

    Discussion

    For values, see Number Formatter Styles.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Type for constants specifying how numbers should be parsed.

    Declaration

    Swift

    struct CFNumberFormatterOptionFlags : RawOptionSetType { init(_ rawValue: CFOptionFlags) init(rawValue rawValue: CFOptionFlags) static var ParseIntegersOnly: CFNumberFormatterOptionFlags { get } }

    Objective-C

    typedef CFOptionFlags CFNumberFormatterOptionFlags;

    Discussion

    For values, see Number Format Options.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Type for constants specifying how numbers should be padded.

    Declaration

    Swift

    enum CFNumberFormatterPadPosition : CFIndex { case BeforePrefix case AfterPrefix case BeforeSuffix case AfterSuffix }

    Objective-C

    typedef CFIndex CFNumberFormatterPadPosition;

    Discussion

    For values, see Padding Positions.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • A reference to a CFNumberFormatter object.

    Declaration

    Swift

    typealias CFNumberFormatterRef = CFNumberFormatter

    Objective-C

    typedef struct __CFNumberFormatter *CFNumberFormatterRef;

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

Constants

Miscellaneous

  • Predefined number format styles.

    Declaration

    Swift

    enum CFNumberFormatterStyle : CFIndex { case NoStyle case DecimalStyle case CurrencyStyle case PercentStyle case ScientificStyle case SpellOutStyle }

    Objective-C

    enum { kCFNumberFormatterNoStyle = 0, kCFNumberFormatterDecimalStyle = 1, kCFNumberFormatterCurrencyStyle = 2, kCFNumberFormatterPercentStyle = 3, kCFNumberFormatterScientificStyle = 4, kCFNumberFormatterSpellOutStyle = 5 };

    Constants

    • NoStyle

      kCFNumberFormatterNoStyle

      Specifies no style.

      Available in iOS 2.0 and later.

    • DecimalStyle

      kCFNumberFormatterDecimalStyle

      Specifies a decimal style format.

      Available in iOS 2.0 and later.

    • CurrencyStyle

      kCFNumberFormatterCurrencyStyle

      Specifies a currency style format.

      Available in iOS 2.0 and later.

    • PercentStyle

      kCFNumberFormatterPercentStyle

      Specifies a percent style format.

      Available in iOS 2.0 and later.

    • ScientificStyle

      kCFNumberFormatterScientificStyle

      Specifies a scientific style format.

      Available in iOS 2.0 and later.

    • SpellOutStyle

      kCFNumberFormatterSpellOutStyle

      Specifies a spelled out format.

      Available in iOS 2.0 and later.

    Discussion

    The format for these number styles is not exact because they depend on the locale, user preference settings, and operating system version. Do not use these constants if you want an exact format (for example, if you are parsing data in a given format). In general, however, you are encouraged to use these styles to accommodate user preferences.

  • The keys used in key-value pairs to specify the value of number formatter properties.

    Declaration

    Swift

    let kCFNumberFormatterCurrencyCode: CFString! let kCFNumberFormatterDecimalSeparator: CFString! let kCFNumberFormatterCurrencyDecimalSeparator: CFString! let kCFNumberFormatterAlwaysShowDecimalSeparator: CFString! let kCFNumberFormatterGroupingSeparator: CFString! let kCFNumberFormatterUseGroupingSeparator: CFString! let kCFNumberFormatterPercentSymbol: CFString! let kCFNumberFormatterZeroSymbol: CFString! let kCFNumberFormatterNaNSymbol: CFString! let kCFNumberFormatterInfinitySymbol: CFString! let kCFNumberFormatterMinusSign: CFString! let kCFNumberFormatterPlusSign: CFString! let kCFNumberFormatterCurrencySymbol: CFString! let kCFNumberFormatterExponentSymbol: CFString! let kCFNumberFormatterMinIntegerDigits: CFString! let kCFNumberFormatterMaxIntegerDigits: CFString! let kCFNumberFormatterMinFractionDigits: CFString! let kCFNumberFormatterMaxFractionDigits: CFString! let kCFNumberFormatterGroupingSize: CFString! let kCFNumberFormatterSecondaryGroupingSize: CFString! let kCFNumberFormatterRoundingMode: CFString! let kCFNumberFormatterRoundingIncrement: CFString! let kCFNumberFormatterFormatWidth: CFString! let kCFNumberFormatterPaddingPosition: CFString! let kCFNumberFormatterPaddingCharacter: CFString! let kCFNumberFormatterDefaultFormat: CFString! let kCFNumberFormatterMultiplier: CFString! let kCFNumberFormatterPositivePrefix: CFString! let kCFNumberFormatterPositiveSuffix: CFString! let kCFNumberFormatterNegativePrefix: CFString! let kCFNumberFormatterNegativeSuffix: CFString! let kCFNumberFormatterPerMillSymbol: CFString! let kCFNumberFormatterInternationalCurrencySymbol: CFString! let kCFNumberFormatterCurrencyGroupingSeparator: CFString! let kCFNumberFormatterIsLenient: CFString! let kCFNumberFormatterUseSignificantDigits: CFString! let kCFNumberFormatterMinSignificantDigits: CFString! let kCFNumberFormatterMaxSignificantDigits: CFString!

    Objective-C

    const CFStringRef kCFNumberFormatterCurrencyCode; const CFStringRef kCFNumberFormatterDecimalSeparator; const CFStringRef kCFNumberFormatterCurrencyDecimalSeparator; const CFStringRef kCFNumberFormatterAlwaysShowDecimalSeparator; const CFStringRef kCFNumberFormatterGroupingSeparator; const CFStringRef kCFNumberFormatterUseGroupingSeparator; const CFStringRef kCFNumberFormatterPercentSymbol; const CFStringRef kCFNumberFormatterZeroSymbol; const CFStringRef kCFNumberFormatterNaNSymbol; const CFStringRef kCFNumberFormatterInfinitySymbol; const CFStringRef kCFNumberFormatterMinusSign; const CFStringRef kCFNumberFormatterPlusSign; const CFStringRef kCFNumberFormatterCurrencySymbol; const CFStringRef kCFNumberFormatterExponentSymbol; const CFStringRef kCFNumberFormatterMinIntegerDigits; const CFStringRef kCFNumberFormatterMaxIntegerDigits; const CFStringRef kCFNumberFormatterMinFractionDigits; const CFStringRef kCFNumberFormatterMaxFractionDigits; const CFStringRef kCFNumberFormatterGroupingSize; const CFStringRef kCFNumberFormatterSecondaryGroupingSize; const CFStringRef kCFNumberFormatterRoundingMode; const CFStringRef kCFNumberFormatterRoundingIncrement; const CFStringRef kCFNumberFormatterFormatWidth; const CFStringRef kCFNumberFormatterPaddingPosition; const CFStringRef kCFNumberFormatterPaddingCharacter; const CFStringRef kCFNumberFormatterDefaultFormat; const CFStringRef kCFNumberFormatterMultiplier; const CFStringRef kCFNumberFormatterPositivePrefix; const CFStringRef kCFNumberFormatterPositiveSuffix; const CFStringRef kCFNumberFormatterNegativePrefix; const CFStringRef kCFNumberFormatterNegativeSuffix; const CFStringRef kCFNumberFormatterPerMillSymbol; const CFStringRef kCFNumberFormatterInternationalCurrencySymbol; const CFStringRef kCFNumberFormatterCurrencyGroupingSeparator; const CFStringRef kCFNumberFormatterIsLenient; const CFStringRef kCFNumberFormatterUseSignificantDigits; const CFStringRef kCFNumberFormatterMinSignificantDigits; const CFStringRef kCFNumberFormatterMaxSignificantDigits;

    Constants

    • kCFNumberFormatterCurrencyCode

      kCFNumberFormatterCurrencyCode

      Specifies the currency code, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterDecimalSeparator

      kCFNumberFormatterDecimalSeparator

      Specifies the decimal separator, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterCurrencyDecimalSeparator

      kCFNumberFormatterCurrencyDecimalSeparator

      Specifies the currency decimal separator, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterAlwaysShowDecimalSeparator

      kCFNumberFormatterAlwaysShowDecimalSeparator

      Specifies if the result of converting a value to a string should always contain the decimal separator, even if the number is an integer.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterGroupingSeparator

      kCFNumberFormatterGroupingSeparator

      Specifies the grouping separator, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterUseGroupingSeparator

      kCFNumberFormatterUseGroupingSeparator

      Specifies if the grouping separator should be used, a CFBoolean object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPercentSymbol

      kCFNumberFormatterPercentSymbol

      Specifies the string that is used to represent the percent symbol, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterZeroSymbol

      kCFNumberFormatterZeroSymbol

      Specifies the string that is used to represent zero, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterNaNSymbol

      kCFNumberFormatterNaNSymbol

      Specifies the string that is used to represent NaN (“not a number”) when values are converted to strings, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterInfinitySymbol

      kCFNumberFormatterInfinitySymbol

      Specifies the string that is used to represent the symbol for infinity, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMinusSign

      kCFNumberFormatterMinusSign

      Specifies the symbol for the minus sign, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPlusSign

      kCFNumberFormatterPlusSign

      Specifies the symbol for the plus sign, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterCurrencySymbol

      kCFNumberFormatterCurrencySymbol

      Specifies the symbol for the currency, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterExponentSymbol

      kCFNumberFormatterExponentSymbol

      Specifies the exponent symbol (“E” or “e”) in the scientific notation of numbers (for example, as in 1.0e+56), a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMinIntegerDigits

      kCFNumberFormatterMinIntegerDigits

      Specifies the minimum number of integer digits before a decimal point, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMaxIntegerDigits

      kCFNumberFormatterMaxIntegerDigits

      Specifies the maximum number of integer digits before a decimal point, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMinFractionDigits

      kCFNumberFormatterMinFractionDigits

      Specifies the minimum number of digits after a decimal point, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMaxFractionDigits

      kCFNumberFormatterMaxFractionDigits

      Specifies the maximum number of digits after a decimal point, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterGroupingSize

      kCFNumberFormatterGroupingSize

      Specifies how often the “thousands” or grouping separator appears, as in “10,000,000”, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterSecondaryGroupingSize

      kCFNumberFormatterSecondaryGroupingSize

      Specifies how often the secondary grouping separator appears, a CFNumber object. See Creating and Using CFNumberFormatter Objects for more information.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterRoundingMode

      kCFNumberFormatterRoundingMode

      Specifies how the last digit is rounded, as when 3.1415926535... is rounded to three decimal places, as in 3.142, a CFNumber object. See “Rounding Modes” for possible values.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterRoundingIncrement

      kCFNumberFormatterRoundingIncrement

      Specifies a positive rounding increment, or 0.0 to disable rounding, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterFormatWidth

      kCFNumberFormatterFormatWidth

      Specifies the width of a formatted number within a string that is either left justified or right justified based on the value of kCFNumberFormatterPaddingPosition, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPaddingPosition

      kCFNumberFormatterPaddingPosition

      Specifies the position of a formatted number within a string, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPaddingCharacter

      kCFNumberFormatterPaddingCharacter

      Specifies the padding character to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterDefaultFormat

      kCFNumberFormatterDefaultFormat

      The original format string for the formatter (given the date and time style and locale specified at creation), a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMultiplier

      kCFNumberFormatterMultiplier

      Specifies the multiplier to use when placing a formatted number within a string, a CFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPositivePrefix

      kCFNumberFormatterPositivePrefix

      Specifies the plus sign prefix symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPositiveSuffix

      kCFNumberFormatterPositiveSuffix

      Specifies the plus sign suffix symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterNegativePrefix

      kCFNumberFormatterNegativePrefix

      Specifies the minus sign prefix symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterNegativeSuffix

      kCFNumberFormatterNegativeSuffix

      Specifies the minus sign suffix symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterPerMillSymbol

      kCFNumberFormatterPerMillSymbol

      Specifies the per mill (1/1000) symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterInternationalCurrencySymbol

      kCFNumberFormatterInternationalCurrencySymbol

      Specifies the international currency symbol to use when placing a formatted number within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterCurrencyGroupingSeparator

      kCFNumberFormatterCurrencyGroupingSeparator

      Specifies the grouping symbol to use when placing a currency value within a string, a CFString object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterIsLenient

      kCFNumberFormatterIsLenient

      Specifies whether the formatter is lenient, aCFBoolean object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterUseSignificantDigits

      kCFNumberFormatterUseSignificantDigits

      Specifies the whether the formatter uses significant digits, a CFBoolean object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMinSignificantDigits

      kCFNumberFormatterMinSignificantDigits

      Specifies the minimum number of significant digits to use, aCFNumber object.

      Available in iOS 2.0 and later.

    • kCFNumberFormatterMaxSignificantDigits

      kCFNumberFormatterMaxSignificantDigits

      Specifies the maximum number of significant digits to use, aCFNumber object.

      Available in iOS 2.0 and later.

    Discussion

    The values for these keys are all CFType objects. The specific types for each key are specified above.

  • These constants are used to specify how numbers should be parsed.

    Declaration

    Swift

    struct CFNumberFormatterOptionFlags : RawOptionSetType { init(_ rawValue: CFOptionFlags) init(rawValue rawValue: CFOptionFlags) static var ParseIntegersOnly: CFNumberFormatterOptionFlags { get } }

    Objective-C

    enum { kCFNumberFormatterParseIntegersOnly = 1 };

    Constants

    • ParseIntegersOnly

      kCFNumberFormatterParseIntegersOnly

      Specifies that only integers should be parsed.

      Available in iOS 2.0 and later.

  • These constants are used to specify how numbers should be rounded.

    Declaration

    Swift

    enum CFNumberFormatterRoundingMode : CFIndex { case RoundCeiling case RoundFloor case RoundDown case RoundUp case RoundHalfEven case RoundHalfDown case RoundHalfUp }

    Objective-C

    typedef enum { kCFNumberFormatterRoundCeiling = 0, kCFNumberFormatterRoundFloor = 1, kCFNumberFormatterRoundDown = 2, kCFNumberFormatterRoundUp = 3, kCFNumberFormatterRoundHalfEven = 4, kCFNumberFormatterRoundHalfDown = 5, kCFNumberFormatterRoundHalfUp = 6 } CFNumberFormatterRoundingMode;

    Constants

    • RoundCeiling

      kCFNumberFormatterRoundCeiling

      Round towards positive infinity.

      Available in iOS 2.0 and later.

    • RoundFloor

      kCFNumberFormatterRoundFloor

      Round towards negative infinity.

      Available in iOS 2.0 and later.

    • RoundDown

      kCFNumberFormatterRoundDown

      Round towards zero.

      Available in iOS 2.0 and later.

    • RoundUp

      kCFNumberFormatterRoundUp

      Round away from zero.

      Available in iOS 2.0 and later.

    • RoundHalfEven

      kCFNumberFormatterRoundHalfEven

      Round towards the nearest integer, or towards an even number if equidistant.

      Available in iOS 2.0 and later.

    • RoundHalfDown

      kCFNumberFormatterRoundHalfDown

      Round towards the nearest integer, or towards zero if equidistant.

      Available in iOS 2.0 and later.

    • RoundHalfUp

      kCFNumberFormatterRoundHalfUp

      Round towards the nearest integer, or away from zero if equidistant.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • These constants are used to specify how numbers should be padded.

    Declaration

    Swift

    enum CFNumberFormatterPadPosition : CFIndex { case BeforePrefix case AfterPrefix case BeforeSuffix case AfterSuffix }

    Objective-C

    typedef enum { kCFNumberFormatterPadBeforePrefix = 0, kCFNumberFormatterPadAfterPrefix = 1, kCFNumberFormatterPadBeforeSuffix = 2, kCFNumberFormatterPadAfterSuffix = 3 };

    Constants

    • BeforePrefix

      kCFNumberFormatterPadBeforePrefix

      Specifies the number of padding characters before the prefix.

      Available in iOS 2.0 and later.

    • AfterPrefix

      kCFNumberFormatterPadAfterPrefix

      Specifies the number of padding characters after the prefix.

      Available in iOS 2.0 and later.

    • BeforeSuffix

      kCFNumberFormatterPadBeforeSuffix

      Specifies the number of padding characters before the suffix.

      Available in iOS 2.0 and later.

    • AfterSuffix

      kCFNumberFormatterPadAfterSuffix

      Specifies the number of padding characters after the suffix.

      Available in iOS 2.0 and later.