| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in Mac OS X v10.0 and later.
|
| Companion guide | |
| Declared in | NSNumberFormatter.h |
Instances of NSNumberFormatter 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. NSNumberFormatter objects can also impose ranges on the numeric values cells can accept.
Many new methods were added to NSNumberFormatter for Mac OS X v10.4 with the intent of making the class interface more like that of CFNumberFormatter, the Core Foundation service on which the class is based. The behavior of an NSNumberFormatter object can conform either to the range of behaviors existing prior to Mac OS X v10.4 or to the range of behavior since that release. (Methods added for and since Mac OS X v10.4 are indicated by a method’s availability statement.) You can determine the current formatter behavior with the formatterBehavior method and you can set the formatter behavior with the setFormatterBehavior: method.
Important:
The pre-Mac OS X v10.4 methods of NSNumberFormatter are not compatible with the methods added for Mac OS X v10.4. An NSNumberFormatter object should not invoke methods in these different behavior groups indiscriminately. Use the old-style methods if you have configured the number-formatter behavior to be NSNumberFormatterBehavior10_0. Use the new methods instead of the older-style ones if you have configured the number-formatter behavior to be NSNumberFormatterBehavior10_4.
Note also that number formatters created in Interface Builder use the Mac OS X v10.0 behavior—see NSNumberFormatter on Mac OS X 10.4.
Nomenclature note: NSNumberFormatter provides several methods (such as setMaximumFractionDigits:) that allow you to manage the number of fraction digits allowed as input by an instance: “fraction digits” are the numbers after the decimal separator (in English locales typically referred to as the “decimal point”).
– setFormatterBehavior:
– formatterBehavior
+ setDefaultFormatterBehavior:
+ defaultFormatterBehavior
– setNumberStyle:
– numberStyle
– setGeneratesDecimalNumbers:
– generatesDecimalNumbers
– setRoundingBehavior:
– roundingBehavior
– setRoundingIncrement:
– roundingIncrement
– setRoundingMode:
– roundingMode
– setFormat:
– formatWidth
– setNegativeFormat:
– negativeFormat
– setPositiveFormat:
– positiveFormat
– setFormatWidth:
– format
– setMultiplier:
– multiplier
– percentSymbol
– setPercentSymbol:
– perMillSymbol
– setPerMillSymbol:
– minusSign
– setMinusSign:
– plusSign
– setPlusSign:
– exponentSymbol
– setExponentSymbol:
– zeroSymbol
– setZeroSymbol:
– nilSymbol
– setNilSymbol:
– notANumberSymbol
– setNotANumberSymbol:
– negativeInfinitySymbol
– setNegativeInfinitySymbol:
– positiveInfinitySymbol
– setPositiveInfinitySymbol:
– setCurrencySymbol:
– currencySymbol
– setCurrencyCode:
– currencyCode
– setInternationalCurrencySymbol:
– internationalCurrencySymbol
– setCurrencyGroupingSeparator:
– currencyGroupingSeparator
– setPositivePrefix:
– positivePrefix
– setPositiveSuffix:
– positiveSuffix
– setNegativePrefix:
– negativePrefix
– setNegativeSuffix:
– negativeSuffix
– setTextAttributesForNegativeValues:
– textAttributesForNegativeValues
– setTextAttributesForPositiveValues:
– textAttributesForPositiveValues
– setAttributedStringForZero:
– attributedStringForZero
– setTextAttributesForZero:
– textAttributesForZero
– setAttributedStringForNil:
– attributedStringForNil
– setTextAttributesForNil:
– textAttributesForNil
– setAttributedStringForNotANumber:
– attributedStringForNotANumber
– setTextAttributesForNotANumber:
– textAttributesForNotANumber
– setTextAttributesForPositiveInfinity:
– textAttributesForPositiveInfinity
– setTextAttributesForNegativeInfinity:
– textAttributesForNegativeInfinity
– setGroupingSeparator:
– groupingSeparator
– setUsesGroupingSeparator:
– usesGroupingSeparator
– setThousandSeparator:
– thousandSeparator
– setHasThousandSeparators:
– hasThousandSeparators
– setDecimalSeparator:
– decimalSeparator
– setAlwaysShowsDecimalSeparator:
– alwaysShowsDecimalSeparator
– setCurrencyDecimalSeparator:
– currencyDecimalSeparator
– setGroupingSize:
– groupingSize
– setSecondaryGroupingSize:
– secondaryGroupingSize
– setAllowsFloats:
– allowsFloats
– setMinimum:
– minimum
– setMaximum:
– maximum
– setMinimumIntegerDigits:
– minimumIntegerDigits
– setMinimumFractionDigits:
– minimumFractionDigits
– setMaximumIntegerDigits:
– maximumIntegerDigits
– setMaximumFractionDigits:
– maximumFractionDigits
– setUsesSignificantDigits:
– usesSignificantDigits
– setMinimumSignificantDigits:
– minimumSignificantDigits
– setMaximumSignificantDigits:
– maximumSignificantDigits
Returns an NSNumberFormatterBehavior constant that indicates default formatter behavior for new instances of NSNumberFormatter.
+ (NSNumberFormatterBehavior)defaultFormatterBehavior
An NSNumberFormatterBehavior constant that indicates default formatter behavior for new instances of NSNumberFormatter.
NSNumberFormatter.h
Sets the default formatter behavior for new instances of NSNumberFormatter .
+ (void)setDefaultFormatterBehavior:(NSNumberFormatterBehavior)behavior
An NSNumberFormatterBehavior constant that indicates the revision of the class providing the default behavior.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver allows floating-point values as input.
- (BOOL)allowsFloats
YES if the receiver allows as input floating-point values (that is, values that include the period character [.]), otherwise NO.
When this method returns NO, only integer values can be provided as input. The default is YES.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver always shows a decimal separator, even if the number is an integer.
- (BOOL)alwaysShowsDecimalSeparator
YES if the receiver always shows a decimal separator, even if the number is an integer, otherwise NO.
NSNumberFormatter.hReturns the attributed string used to display nil values.
- (NSAttributedString *)attributedStringForNil
The attributed string used to display nil values.
By default nil values are displayed as an empty string.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.
NSNumberFormatter.hReturns the attributed string used to display “not a number” values.
- (NSAttributedString *)attributedStringForNotANumber
The attributed string used to display “not a number” values.
By default “not a number” values are displayed as the string “NaN”.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.
NSNumberFormatter.hReturns the attributed string used to display zero values.
- (NSAttributedString *)attributedStringForZero
The attributed string used to display zero values.
By default zero values are displayed according to the format specified for positive values; for more discussion of this subject see Data Formatting Programming Guide for Cocoa.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.
NSNumberFormatter.hReturns the receiver’s currency code as a string.
- (NSString *)currencyCode
The receiver’s currency code as a string.
A currency code is a three-letter code that is, in most cases, composed of a country’s two-character Internet country code plus an extra character to denote the currency unit. For example, the currency code for the Australian dollar is “AUD”. Currency codes are based on the ISO 4217 standard.
NSNumberFormatter.hReturns the receiver’s currency decimal separator as a string.
- (NSString *)currencyDecimalSeparator
The receiver’s currency decimal separator as a string.
NSNumberFormatter.hReturns the currency grouping separator for the receiver.
- (NSString *)currencyGroupingSeparator
The currency grouping separator for the receiver.
NSNumberFormatter.hReturns the receiver’s local currency symbol.
- (NSString *)currencySymbol
A country typically has a local currency symbol and an international currency symbol. The local symbol is used within the country, while the international currency symbol is used in international contexts to specify that country’s currency unambiguously. The local currency symbol is often represented by a Unicode code point.
NSNumberFormatter.hReturns a string containing the character the receiver uses to represent decimal separators.
- (NSString *)decimalSeparator
A string containing the character the receiver uses to represent decimal separators.
The return value doesn’t indicate whether decimal separators are enabled.
NSNumberFormatter.hReturns the string the receiver uses as an exponent symbol.
- (NSString *)exponentSymbol
The string the receiver uses as an exponent symbol.
The exponent symbol is the “E” or “e” in the scientific notation of numbers, as in 1.0e+56.
NSNumberFormatter.hReturns the format used by the receiver.
- (NSString *)format
The format used by the receiver.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.
NSNumberFormatter.hReturns an NSNumberFormatterBehavior constant that indicates the formatter behavior of the receiver.
- (NSNumberFormatterBehavior)formatterBehavior
An NSNumberFormatterBehavior constant that indicates the formatter behavior of the receiver.
NSNumberFormatter.hReturns the format width of the receiver.
- (NSUInteger)formatWidth
The format width is the number of characters of a formatted number within a string that is either left justified or right justified based on the value returned from paddingPosition.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver creates instances of NSDecimalNumber when it converts strings to number objects.
- (BOOL)generatesDecimalNumbers
YES if the receiver creates instances of NSDecimalNumber when it converts strings to number objects, NO if it creates instance of NSNumber.
NSNumberFormatter.hReturns by reference a cell-content object after creating it from a range of characters in a given string.
- (BOOL)getObjectValue:(out id *)anObject forString:(NSString *)aString range:(inout NSRange *)rangep error:(out NSError **)error
On return, contains an instance of NSDecimalNumber or NSNumber based on the current value of generatesDecimalNumbers. The default is to return NSDecimalNumber instances
A string object with the range of characters specified in rangep that is used to create anObject.
A range of characters in aString. On return, contains the actual range of characters used to create the object.
If an error occurs, upon return contains an NSError object that explains the reason why the conversion failed. If you pass in nil for error you are indicating that you are not interested in error information.
YES if the conversion from string to cell-content object was successful, otherwise NO.
If there is an error, the delegate (if any) of the control object managing the cell can then respond to the failure in the NSController delegation method control:didFailToFormatString:errorDescription:.
NSNumberFormatter.hReturns a string containing the receiver’s grouping separator.
- (NSString *)groupingSeparator
A string containing the receiver’s grouping separator.
For example, the grouping separator used in the United States is the comma (“10,000”) whereas in France it is the period (“10.000”).
NSNumberFormatter.hReturns the receiver’s primary grouping size.
- (NSUInteger)groupingSize
The receiver’s primary grouping size.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver’s format includes thousand separators.
- (BOOL)hasThousandSeparators
YES if the receiver’s format includes thousand separators, otherwise NO.
The default is NO.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.
NSNumberFormatter.hReturns the international currency symbol used by the receiver.
- (NSString *)internationalCurrencySymbol
A country typically has a local currency symbol and an international currency symbol. The local symbol is used within the country, while the international currency symbol is used in international contexts to specify that country’s currency unambiguously. The international currency symbol is often represented by a Unicode code point.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver uses heuristics to guess at the date which is intended by a string.
- (BOOL)isLenient
YES if the receiver uses heuristics to guess at the date which is intended by the string, otherwise NO.
NSNumberFormatter.hReturns a Boolean value that indicates whether partial string validation is enabled.
- (BOOL)isPartialStringValidationEnabled
YES if partial string validation is enabled, otherwise NO.
NSNumberFormatter.hReturns the locale of the receiver.
- (NSLocale *)locale
The locale of the receiver.
A number formatter’s locale specifies default localization attributes, such as ISO country and language codes, currency code, calendar, system of measurement, and decimal separator.
NSNumberFormatter.hReturns a Boolean value that indicates whether the receiver localizes formats.
- (BOOL)localizesFormat
YES if the receiver localizes formats, otherwise NO.
The default is NO.
This method is for use with formatters using NSNumberFormatterBehavior10_0 behavior.