2 * Copyright (c) 2011 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 /* CFNumberFormatter.h
25 Copyright (c) 2003-2011, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFNUMBERFORMATTER__)
29 #define __COREFOUNDATION_CFNUMBERFORMATTER__ 1
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFNumber.h>
33 #include <CoreFoundation/CFLocale.h>
37 typedef struct __CFNumberFormatter
*CFNumberFormatterRef
;
39 // CFNumberFormatters are not thread-safe. Do not use one from multiple threads!
42 CFTypeID
CFNumberFormatterGetTypeID(void);
44 enum { // number format styles
45 kCFNumberFormatterNoStyle
= 0,
46 kCFNumberFormatterDecimalStyle
= 1,
47 kCFNumberFormatterCurrencyStyle
= 2,
48 kCFNumberFormatterPercentStyle
= 3,
49 kCFNumberFormatterScientificStyle
= 4,
50 kCFNumberFormatterSpellOutStyle
= 5
52 typedef CFIndex CFNumberFormatterStyle
;
56 CFNumberFormatterRef
CFNumberFormatterCreate(CFAllocatorRef allocator
, CFLocaleRef locale
, CFNumberFormatterStyle style
);
57 // Returns a CFNumberFormatter, localized to the given locale, which
58 // will format numbers to the given style.
61 CFLocaleRef
CFNumberFormatterGetLocale(CFNumberFormatterRef formatter
);
64 CFNumberFormatterStyle
CFNumberFormatterGetStyle(CFNumberFormatterRef formatter
);
65 // Get the properties with which the number formatter was created.
68 CFStringRef
CFNumberFormatterGetFormat(CFNumberFormatterRef formatter
);
71 void CFNumberFormatterSetFormat(CFNumberFormatterRef formatter
, CFStringRef formatString
);
72 // Set the format description string of the number formatter. This
73 // overrides the style settings. The format of the format string
74 // is as defined by the ICU library, and is similar to that found
75 // in Microsoft Excel and NSNumberFormatter (and Java I believe).
76 // The number formatter starts with a default format string defined
77 // by the style argument with which it was created.
81 CFStringRef
CFNumberFormatterCreateStringWithNumber(CFAllocatorRef allocator
, CFNumberFormatterRef formatter
, CFNumberRef number
);
84 CFStringRef
CFNumberFormatterCreateStringWithValue(CFAllocatorRef allocator
, CFNumberFormatterRef formatter
, CFNumberType numberType
, const void *valuePtr
);
85 // Create a string representation of the given number or value
86 // using the current state of the number formatter.
90 kCFNumberFormatterParseIntegersOnly
= 1 /* only parse integers */
92 typedef CFOptionFlags CFNumberFormatterOptionFlags
;
95 CFNumberRef
CFNumberFormatterCreateNumberFromString(CFAllocatorRef allocator
, CFNumberFormatterRef formatter
, CFStringRef string
, CFRange
*rangep
, CFOptionFlags options
);
98 Boolean
CFNumberFormatterGetValueFromString(CFNumberFormatterRef formatter
, CFStringRef string
, CFRange
*rangep
, CFNumberType numberType
, void *valuePtr
);
99 // Parse a string representation of a number using the current state
100 // of the number formatter. The range parameter specifies the range
101 // of the string in which the parsing should occur in input, and on
102 // output indicates the extent that was used; this parameter can
103 // be NULL, in which case the whole string may be used. The
104 // return value indicates whether some number was computed and
105 // (if valuePtr is not NULL) stored at the location specified by
106 // valuePtr. The numberType indicates the type of value pointed
111 void CFNumberFormatterSetProperty(CFNumberFormatterRef formatter
, CFStringRef key
, CFTypeRef value
);
114 CFTypeRef
CFNumberFormatterCopyProperty(CFNumberFormatterRef formatter
, CFStringRef key
);
115 // Set and get various properties of the number formatter, the set of
116 // which may be expanded in the future.
118 CF_EXPORT
const CFStringRef kCFNumberFormatterCurrencyCode
; // CFString
119 CF_EXPORT
const CFStringRef kCFNumberFormatterDecimalSeparator
; // CFString
120 CF_EXPORT
const CFStringRef kCFNumberFormatterCurrencyDecimalSeparator
; // CFString
121 CF_EXPORT
const CFStringRef kCFNumberFormatterAlwaysShowDecimalSeparator
; // CFBoolean
122 CF_EXPORT
const CFStringRef kCFNumberFormatterGroupingSeparator
; // CFString
123 CF_EXPORT
const CFStringRef kCFNumberFormatterUseGroupingSeparator
; // CFBoolean
124 CF_EXPORT
const CFStringRef kCFNumberFormatterPercentSymbol
; // CFString
125 CF_EXPORT
const CFStringRef kCFNumberFormatterZeroSymbol
; // CFString
126 CF_EXPORT
const CFStringRef kCFNumberFormatterNaNSymbol
; // CFString
127 CF_EXPORT
const CFStringRef kCFNumberFormatterInfinitySymbol
; // CFString
128 CF_EXPORT
const CFStringRef kCFNumberFormatterMinusSign
; // CFString
129 CF_EXPORT
const CFStringRef kCFNumberFormatterPlusSign
; // CFString
130 CF_EXPORT
const CFStringRef kCFNumberFormatterCurrencySymbol
; // CFString
131 CF_EXPORT
const CFStringRef kCFNumberFormatterExponentSymbol
; // CFString
132 CF_EXPORT
const CFStringRef kCFNumberFormatterMinIntegerDigits
; // CFNumber
133 CF_EXPORT
const CFStringRef kCFNumberFormatterMaxIntegerDigits
; // CFNumber
134 CF_EXPORT
const CFStringRef kCFNumberFormatterMinFractionDigits
; // CFNumber
135 CF_EXPORT
const CFStringRef kCFNumberFormatterMaxFractionDigits
; // CFNumber
136 CF_EXPORT
const CFStringRef kCFNumberFormatterGroupingSize
; // CFNumber
137 CF_EXPORT
const CFStringRef kCFNumberFormatterSecondaryGroupingSize
; // CFNumber
138 CF_EXPORT
const CFStringRef kCFNumberFormatterRoundingMode
; // CFNumber
139 CF_EXPORT
const CFStringRef kCFNumberFormatterRoundingIncrement
; // CFNumber
140 CF_EXPORT
const CFStringRef kCFNumberFormatterFormatWidth
; // CFNumber
141 CF_EXPORT
const CFStringRef kCFNumberFormatterPaddingPosition
; // CFNumber
142 CF_EXPORT
const CFStringRef kCFNumberFormatterPaddingCharacter
; // CFString
143 CF_EXPORT
const CFStringRef kCFNumberFormatterDefaultFormat
; // CFString
144 CF_EXPORT
const CFStringRef kCFNumberFormatterMultiplier
; // CFNumber
145 CF_EXPORT
const CFStringRef kCFNumberFormatterPositivePrefix
; // CFString
146 CF_EXPORT
const CFStringRef kCFNumberFormatterPositiveSuffix
; // CFString
147 CF_EXPORT
const CFStringRef kCFNumberFormatterNegativePrefix
; // CFString
148 CF_EXPORT
const CFStringRef kCFNumberFormatterNegativeSuffix
; // CFString
149 CF_EXPORT
const CFStringRef kCFNumberFormatterPerMillSymbol
; // CFString
150 CF_EXPORT
const CFStringRef kCFNumberFormatterInternationalCurrencySymbol
; // CFString
151 CF_EXPORT
const CFStringRef kCFNumberFormatterCurrencyGroupingSeparator
CF_AVAILABLE(10_5
, 2_0
); // CFString
152 CF_EXPORT
const CFStringRef kCFNumberFormatterIsLenient
CF_AVAILABLE(10_5
, 2_0
); // CFBoolean
153 CF_EXPORT
const CFStringRef kCFNumberFormatterUseSignificantDigits
CF_AVAILABLE(10_5
, 2_0
); // CFBoolean
154 CF_EXPORT
const CFStringRef kCFNumberFormatterMinSignificantDigits
CF_AVAILABLE(10_5
, 2_0
); // CFNumber
155 CF_EXPORT
const CFStringRef kCFNumberFormatterMaxSignificantDigits
CF_AVAILABLE(10_5
, 2_0
); // CFNumber
158 kCFNumberFormatterRoundCeiling
= 0,
159 kCFNumberFormatterRoundFloor
= 1,
160 kCFNumberFormatterRoundDown
= 2,
161 kCFNumberFormatterRoundUp
= 3,
162 kCFNumberFormatterRoundHalfEven
= 4,
163 kCFNumberFormatterRoundHalfDown
= 5,
164 kCFNumberFormatterRoundHalfUp
= 6
166 typedef CFIndex CFNumberFormatterRoundingMode
;
169 kCFNumberFormatterPadBeforePrefix
= 0,
170 kCFNumberFormatterPadAfterPrefix
= 1,
171 kCFNumberFormatterPadBeforeSuffix
= 2,
172 kCFNumberFormatterPadAfterSuffix
= 3
174 typedef CFIndex CFNumberFormatterPadPosition
;
178 Boolean
CFNumberFormatterGetDecimalInfoForCurrencyCode(CFStringRef currencyCode
, int32_t *defaultFractionDigits
, double *roundingIncrement
);
179 // Returns the number of fraction digits that should be displayed, and
180 // the rounding increment (or 0.0 if no rounding is done by the currency)
181 // for the given currency. Returns false if the currency code is unknown
182 // or the information is not available.
183 // Not localized because these are properties of the currency.
187 #endif /* ! __COREFOUNDATION_CFNUMBERFORMATTER__ */