CFNumberFormatter

Overview

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.

Topics

Creating a Number Formatter

CFNumberFormatterCreate

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

Configuring a Number Formatter

CFNumberFormatterSetFormat

Sets the format string of a number formatter.

CFNumberFormatterSetProperty

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

Formatting Values

CFNumberFormatterCreateNumberFromString

Returns a number object representing a given string.

CFNumberFormatterCreateStringWithNumber

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

CFNumberFormatterCreateStringWithValue

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

CFNumberFormatterGetDecimalInfoForCurrencyCode

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

CFNumberFormatterGetValueFromString

Returns a number or value representing a given string.

Examining a Number Formatter

CFNumberFormatterCopyProperty

Returns a copy of a number formatter’s value for a given key.

CFNumberFormatterGetFormat

Returns a format string for the given number formatter object.

CFNumberFormatterGetLocale

Returns the locale object used to create the given number formatter object.

CFNumberFormatterGetStyle

Returns the number style used to create the given number formatter object.

Getting the CFNumberFormatter Type ID

CFNumberFormatterGetTypeID

Returns the type identifier for the CFNumberFormatter opaque type.

Data Types

CFNumberFormatterStyle

Type for constants specifying a formatter style.

CFNumberFormatterOptionFlags

Type for constants specifying how numbers should be parsed.

CFNumberFormatterPadPosition

Type for constants specifying how numbers should be padded.

CFNumberFormatterRef

A reference to a CFNumberFormatter object.

Constants

Number Formatter Styles

Predefined number format styles.

Number Formatter Property Keys

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

Number Format Options

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

CFNumberFormatterRoundingMode

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

Padding Positions

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

See Also

Opaque Types

CFFileDescriptor

The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.

CFStringTokenizer

CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.