| Derived from | |
| Framework | CoreFoundation/CoreFoundation.h |
| Companion guide | |
| Declared in | CFNumberFormatter.h |
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 itself is defined by Unicode Technical Standard #35.
Note that CFNumberFormatter is not thread-safe. Do not use a single instance from multiple threads.
The CFNumberFormatter opaque type is available in Mac OS X v10.3 and later.
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.
CFNumberFormatterCreateNumberFromString
CFNumberFormatterCreateStringWithNumber
CFNumberFormatterCreateStringWithValue
CFNumberFormatterGetDecimalInfoForCurrencyCode
CFNumberFormatterGetValueFromString
CFNumberFormatterCopyProperty
CFNumberFormatterGetFormat
CFNumberFormatterGetLocale
CFNumberFormatterGetStyle
Returns a copy of a number formatter’s value for a given key.
CFTypeRef CFNumberFormatterCopyProperty ( CFNumberFormatterRef formatter, CFStringRef key );
The number formatter to examine.
A property key. See “Number Formatter Property Keys” for valid values.
A CFType object that is a copy of the property value for key. Returns NULL if there is no value specified for key. Ownership follows the Create Rule.
CFNumberFormatter.hCreates a new CFNumberFormatter object, localized to the given locale, which will format numbers to the given style.
CFNumberFormatterRef CFNumberFormatterCreate ( CFAllocatorRef allocator, CFLocaleRef locale, CFNumberFormatterStyle style );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
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.
A number style. See “Number Formatter Styles” for possible values.
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 Create Rule.
CFNumberFormatter.hReturns a number object representing a given string.
CFNumberRef CFNumberFormatterCreateNumberFromString ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFOptionFlags options );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The number formatter to use.
The string to parse.
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).
Specifies various configuration options to change the behavior of the parse. Currently, kCFNumberFormatterParseIntegersOnly is the only possible value for this parameter.
A new number that represents the given string. Returns NULL if there was a problem creating the number. Ownership follows the Create Rule.
CFNumberFormatter.hReturns a string representation of the given number using the specified number formatter.
CFStringRef CFNumberFormatterCreateStringWithNumber ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberRef number );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The number formatter to use.
The number from which to create a string representation.
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 Create Rule.
CFNumberFormatter.hReturns a string representation of the given number or value using the specified number formatter.
CFStringRef CFNumberFormatterCreateStringWithValue ( CFAllocatorRef allocator, CFNumberFormatterRef formatter, CFNumberType numberType, const void *valuePtr );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The number formatter to use.
The type of value that valuePtr references. Valid values are listed in CFNumberType.
A pointer to the value to be converted.
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 Create Rule.
CFNumberFormatter.hReturns the number of fraction digits that should be displayed, and the rounding increment, for a given currency.
Boolean CFNumberFormatterGetDecimalInfoForCurrencyCode ( CFStringRef currencyCode, int32_t *defaultFractionDigits, double *roundingIncrement );
A string containing a ISO 4217 3-letter currency code. For example, AUD for Australian Dollars, EUR for Euros.
Upon return, contains the number of fraction digits that should be displayed for the currency specified by currencyCode.
Upon return, contains the rounding increment for the currency specified by currencyCode, or 0.0 if no rounding is done by the currency.
true if the information was obtained successfully, otherwise false (for example, if the currency code is unknown or the information is not available).
The returned values are not localized because these are properties of the currency.
CFNumberFormatter.hReturns a format string for the given number formatter object.
CFStringRef CFNumberFormatterGetFormat ( CFNumberFormatterRef formatter );
The number formatter to examine.
The format string for formatter as was specified by calling the CFNumberFormatterSetFormat function, or derived from the number formatter’s style. The format of this string is defined by Unicode Technical Standard #35.. Ownership follows the Get Rule.
CFNumberFormatter.hReturns the locale object used to create the given number formatter object.
CFLocaleRef CFNumberFormatterGetLocale ( CFNumberFormatterRef formatter );
The number formatter to examine.
The locale used to create formatter. Ownership follows the Get Rule.
CFNumberFormatter.hReturns the number style used to create the given number formatter object.
CFNumberFormatterStyle CFNumberFormatterGetStyle ( CFNumberFormatterRef formatter );
The number formatter to examine.
The number style used to create formatter.
CFNumberFormatter.h
Returns the type identifier for the CFNumberFormatter opaque type.
CFTypeID CFNumberFormatterGetTypeID ( void );
The type identifier for the CFNumberFormatter opaque type.
CFNumberFormatter.hReturns a number or value representing a given string.
Boolean CFNumberFormatterGetValueFromString ( CFNumberFormatterRef formatter, CFStringRef string, CFRange *rangep, CFNumberType numberType, void *valuePtr );
The number formatter to use.
The string to parse.
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).
The type of value that valuePtr references. Valid values are listed in CFNumberType.
Upon return, contains a number or value representing the string in the specified format. You are responsible for releasing this value.
true if the string was parsed successfully, otherwise false.
CFNumberFormatter.h
Sets the format string of a number formatter.
void CFNumberFormatterSetFormat ( CFNumberFormatterRef formatter, CFStringRef formatString );
The number formatter to modify.
The format string to be used by formatter. The format of this string is defined by Unicode Technical Standard #35.
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.
CFNumberFormatter.hSets a number formatter property using a key-value pair.
void CFNumberFormatterSetProperty ( CFNumberFormatterRef formatter, CFStringRef key, CFTypeRef value );
The number formatter to modify.
The name of the property of formatter to set. See “Number Formatter Property Keys” for a description of possible values.
The value of the specified key. This must be an instance of the correct CFType object for the corresponding key.
CFNumberFormatter.hType for constants specifying how numbers should be parsed.
typedef CFOptionFlags CFNumberFormatterOptionFlags;
For values, see “Number Format Options.”
CFNumberFormatter.hType for constants specifying how numbers should be padded.
typedef CFIndex CFNumberFormatterPadPosition;
For values, see “Padding Positions.”
CFNumberFormatter.hA reference to a CFNumberFormatter object.
typedef struct __CFNumberFormatter *CFNumberFormatterRef;
CFNumberFormatter.hType for constants specifying a formatter style.
typedef CFIndex CFNumberFormatterStyle;
For values, see “Number Formatter Styles.”
CFNumberFormatter.hPredefined number format styles.
enum {
kCFNumberFormatterNoStyle = 0,
kCFNumberFormatterDecimalStyle = 1,
kCFNumberFormatterCurrencyStyle = 2,
kCFNumberFormatterPercentStyle = 3,
kCFNumberFormatterScientificStyle = 4,
kCFNumberFormatterSpellOutStyle = 5
};
kCFNumberFormatterNoStyleSpecifies no style.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterDecimalStyleSpecifies a decimal style format.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterCurrencyStyleSpecifies a currency style format.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPercentStyleSpecifies a percent style format.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterScientificStyleSpecifies a scientific style format.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterSpellOutStyleSpecifies a spelled out format.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
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.
CFNumberFormatter.h
The keys used in key-value pairs to specify the value of number formatter properties.
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;
kCFNumberFormatterCurrencyCodeSpecifies the currency code, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterDecimalSeparatorSpecifies the decimal separator, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterCurrencyDecimalSeparatorSpecifies the currency decimal separator, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterAlwaysShowDecimalSeparatorSpecifies 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 Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterGroupingSeparatorSpecifies the grouping separator, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterUseGroupingSeparatorSpecifies if the grouping separator should be used, a CFBoolean object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPercentSymbolSpecifies the string that is used to represent the percent symbol, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterZeroSymbolSpecifies the string that is used to represent zero, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterNaNSymbolSpecifies the string that is used to represent NaN (“not a number”) when values are converted to strings, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterInfinitySymbolSpecifies the string that is used to represent the symbol for infinity, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMinusSignSpecifies the symbol for the minus sign, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPlusSignSpecifies the symbol for the plus sign, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterCurrencySymbolSpecifies the symbol for the currency, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterExponentSymbolSpecifies the exponent symbol (“E” or “e”) in the scientific notation of numbers (for example, as in 1.0e+56), a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMinIntegerDigitsSpecifies the minimum number of integer digits before a decimal point, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMaxIntegerDigitsSpecifies the maximum number of integer digits before a decimal point, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMinFractionDigitsSpecifies the minimum number of digits after a decimal point, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMaxFractionDigitsSpecifies the maximum number of digits after a decimal point, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterGroupingSizeSpecifies how often the “thousands” or grouping separator appears, as in “10,000,000”, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterSecondaryGroupingSizeSpecifies how often the secondary grouping separator appears, a CFNumber object. See Unicode Technical Standard #35 for more information.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundingModeSpecifies 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 Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundingIncrementSpecifies a positive rounding increment, or 0.0 to disable rounding, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterFormatWidthSpecifies 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 Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPaddingPositionSpecifies the position of a formatted number within a string, a CFNumber object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPaddingCharacterSpecifies the padding character to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterDefaultFormatThe original format string for the formatter (given the date and time style and locale specified at creation), a CFString object.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMultiplierSpecifies the multiplier to use when placing a formatted number within a string, a CFNumber object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPositivePrefixSpecifies the plus sign prefix symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPositiveSuffixSpecifies the plus sign suffix symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterNegativePrefixSpecifies the minus sign prefix symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterNegativeSuffixSpecifies the minus sign suffix symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPerMillSymbolSpecifies the per mill (1/1000) symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterInternationalCurrencySymbolSpecifies the international currency symbol to use when placing a formatted number within a string, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterCurrencyGroupingSeparatorSpecifies the grouping symbol to use when placing a currency value within a string, a CFString object.
Available in Mac OS X v10.5 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterIsLenientSpecifies whether the formatter is lenient, aCFBoolean object.
Available in Mac OS X v10.5 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterUseSignificantDigitsSpecifies the whether the formatter uses significant digits, a CFBoolean object.
Available in Mac OS X v10.5 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMinSignificantDigitsSpecifies the minimum number of significant digits to use, aCFNumber object.
Available in Mac OS X v10.5 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterMaxSignificantDigitsSpecifies the maximum number of significant digits to use, aCFNumber object.
Available in Mac OS X v10.5 and later.
Declared in CFNumberFormatter.h.
The values for these keys are all CFType objects. The specific types for each key are specified above.
CFNumberFormatter.h
These constants are used to specify how numbers should be parsed.
enum {
kCFNumberFormatterParseIntegersOnly = 1
};
kCFNumberFormatterParseIntegersOnlySpecifies that only integers should be parsed.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
CFNumberFormatter.h
These constants are used to specify how numbers should be rounded.
typedef enum {
kCFNumberFormatterRoundCeiling = 0,
kCFNumberFormatterRoundFloor = 1,
kCFNumberFormatterRoundDown = 2,
kCFNumberFormatterRoundUp = 3,
kCFNumberFormatterRoundHalfEven = 4,
kCFNumberFormatterRoundHalfDown = 5,
kCFNumberFormatterRoundHalfUp = 6
} CFNumberFormatterRoundingMode;
kCFNumberFormatterRoundCeilingRound up to next larger number with the proper number of fraction digits.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundFloorRound down to next larger number with the proper number of fraction digits.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundDownRound down to next larger number with the proper number of fraction digits.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundUpRound up to next larger number with the proper number of fraction digits.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundHalfEvenRound the last digit, when followed by a 5, toward an even digit (.25 -> .2, .35 -> .4)
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundHalfDownRound down when a 5 follows putative last digit.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterRoundHalfUpRound up when a 5 follows putative last digit.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
CFNumberFormatter.h
These constants are used to specify how numbers should be padded.
typedef enum {
kCFNumberFormatterPadBeforePrefix = 0,
kCFNumberFormatterPadAfterPrefix = 1,
kCFNumberFormatterPadBeforeSuffix = 2,
kCFNumberFormatterPadAfterSuffix = 3
};
kCFNumberFormatterPadBeforePrefixSpecifies the number of padding characters before the prefix.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPadAfterPrefixSpecifies the number of padding characters after the prefix.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPadBeforeSuffixSpecifies the number of padding characters before the suffix.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
kCFNumberFormatterPadAfterSuffixSpecifies the number of padding characters after the suffix.
Available in Mac OS X v10.3 and later.
Declared in CFNumberFormatter.h.
CFNumberFormatter.h
© 2003, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-05-23)