Up

NSNumberFormatter class reference

Authors

Fred Kiefer (FredKiefer@gmx.de)
Richard Frith-Macdonald (rfm@gnu.org)

Version: 27578

Date: 2009-01-12 12:48:46 +0000 (Mon, 12 Jan 2009)

Copyright: (C) 2000 Free Software Foundation, Inc.

Software documentation for the NSNumberFormatter class

NSNumberFormatter : NSFormatter

Declared in:
Foundation/NSNumberFormatter.h
Availability: MacOS-X 10.0.0

This class is currently not implemented in GNUstep! All set methods will work, but stringForObject: will ignore the format completely. The documentation below describes what the behavior SHOULD be...

A specialization of the NSFormatter class for generating string representations of numbers NSNumber and NSDecimalNumber instances) and for parsing numeric values in strings.

See the NSFormatter documentation for description of the basic methods for formatting and parsing that are available.

There are no convenience initializers or constructors for this class. Instead, to obtain an instance, call alloc init and then -setFormat: .

The basic format of a format string uses "#" signs to represent digits, and other characters to represent themselves, in a context-dependent way. Thus, for example, @"#,###.00" means to print the number ending in.00 if it has no decimal part, otherwise print two decimal places, and to print one comma if it is greater than 1000. Thus, 1000 prints as "1,000.00", and 1444555.979 prints as "1444,555.98" (see -setRoundingBehavior:).

After setting the format, you may change the thousands separator and decimal point using set methods, or by calling -setLocalizesFormat: .

You may set separate formats to be used for positive numbers, negative numbers, and zero independently.

In addition, this class supports attributed strings (see NSAttributedString ), so that you can specify font and color attributes, among others, to display aspects of a number. You can assign specific sets of attributes for positive and negative numbers, and for specific cases including 0, NaN, and nil...


Instance Variables

Method summary

allowsFloats 

- (BOOL) allowsFloats;
Availability: MacOS-X 10.0.0

Returns whether number parsing will accept floating point values or generate an exception (only int values are valid). Default is YES.

attributedStringForNil 

- (NSAttributedString*) attributedStringForNil;
Availability: MacOS-X 10.0.0

Returns the exact attributed string used for nil values. By default this is an empty string.

attributedStringForNotANumber 

- (NSAttributedString*) attributedStringForNotANumber;
Availability: MacOS-X 10.0.0

Returns the exact attributed string used for NaN values. By default this is the string "NaN" with no attributes.

attributedStringForZero 

- (NSAttributedString*) attributedStringForZero;
Availability: MacOS-X 10.0.0

Returns the exact attributed string used for zero values. By default this is based on the format for zero values, if set, or the format for positive values otherwise.

decimalSeparator 

- (NSString*) decimalSeparator;
Availability: MacOS-X 10.0.0

Returns thousands separator used; default is '.'.

format 

- (NSString*) format;
Availability: MacOS-X 10.0.0

Returns the format string this instance was initialized with.

hasThousandSeparators 

- (BOOL) hasThousandSeparators;
Availability: MacOS-X 10.0.0

Returns whether thousands separator should be used, regardless of whether it is set in format. (Default is YES if explicitly set in format.)

localizesFormat 

- (BOOL) localizesFormat;
Availability: MacOS-X 10.0.0

Returns whether this format should defer to the locale in determining thousands separator and decimal point. The default is to NOT localize.

maximum 

- (NSDecimalNumber*) maximum;
Availability: MacOS-X 10.0.0

Returns maximum value that will be accepted as valid in number parsing. Default is none.

minimum 

- (NSDecimalNumber*) minimum;
Availability: MacOS-X 10.0.0

Returns minimum value that will be accepted as valid in number parsing. Default is none.

negativeFormat 

- (NSString*) negativeFormat;
Availability: MacOS-X 10.0.0

Returns format used for negative numbers.

numberFromString: 

- (NSNumber*) numberFromString: (NSString*)string;
Availability: MacOS-X 10.0.0

Returns the number for this string.

positiveFormat 

- (NSString*) positiveFormat;
Availability: MacOS-X 10.0.0

Returns format used for positive numbers.

roundingBehavior 

- (NSDecimalNumberHandler*) roundingBehavior;
Availability: MacOS-X 10.0.0

Returns object specifying the rounding behavior used when truncating decimal digits in formats. Default is [NSDecimalNumberHandler +defaultDecimalNumberHandler] .

setAllowsFloats: 

- (void) setAllowsFloats: (BOOL)flag;
Availability: MacOS-X 10.0.0

Sets whether number parsing will accept floating point values or generate an exception (only int values are valid). Default is YES.

setAttributedStringForNil: 

- (void) setAttributedStringForNil: (NSAttributedString*)newAttributedString;
Availability: MacOS-X 10.0.0

Sets the exact attributed string used for nil values. By default this is an empty string.

setAttributedStringForNotANumber: 

- (void) setAttributedStringForNotANumber: (NSAttributedString*)newAttributedString;
Availability: MacOS-X 10.0.0

Sets the exact attributed string used for NaN values. By default this is the string "NaN" with no attributes.

setAttributedStringForZero: 

- (void) setAttributedStringForZero: (NSAttributedString*)newAttributedString;
Availability: MacOS-X 10.0.0

Sets the exact attributed string used for zero values. By default this is based on the format for zero values, if set, or the format for positive values otherwise.

setDecimalSeparator: 

- (void) setDecimalSeparator: (NSString*)newSeparator;
Availability: MacOS-X 10.0.0

Sets thousands separator used; default is '.'.

setFormat: 

- (void) setFormat: (NSString*)aFormat;
Availability: MacOS-X 10.0.0

Sets format string. See class description for more information.

setHasThousandSeparators: 

- (void) setHasThousandSeparators: (BOOL)flag;
Availability: MacOS-X 10.0.0

Sets whether thousands separator should be used, regardless of whether it is set in format. (Default is YES if explicitly set in format.)

setLocalizesFormat: 

- (void) setLocalizesFormat: (BOOL)flag;
Availability: MacOS-X 10.0.0

Set whether this format should defer to the locale in determining thousands separator and decimal point. The default is to NOT localize.

setMaximum: 

- (void) setMaximum: (NSDecimalNumber*)aMaximum;
Availability: MacOS-X 10.0.0

Sets maximum value that will be accepted as valid in number parsing. Default is none.

setMinimum: 

- (void) setMinimum: (NSDecimalNumber*)aMinimum;
Availability: MacOS-X 10.0.0

Sets minimum value that will be accepted as valid in number parsing. Default is none.

setNegativeFormat: 

- (void) setNegativeFormat: (NSString*)aFormat;
Availability: MacOS-X 10.0.0

Sets format used for negative numbers. See class description for more information.

setPositiveFormat: 

- (void) setPositiveFormat: (NSString*)aFormat;
Availability: MacOS-X 10.0.0

Sets format used for positive numbers. See class description for more information.

setRoundingBehavior: 

- (void) setRoundingBehavior: (NSDecimalNumberHandler*)newRoundingBehavior;
Availability: MacOS-X 10.0.0

Sets object specifying the rounding behavior used when truncating decimal digits in formats. Default is [NSDecimalNumberHandler +defaultDecimalNumberHandler] .

setTextAttributesForNegativeValues: 

- (void) setTextAttributesForNegativeValues: (NSDictionary*)newAttributes;
Availability: MacOS-X 10.0.0

Sets the attributes to apply to negative values (whole string), when -attributedStringForObjectValue:withDefaultAttributes: is called. Default is none.

setTextAttributesForPositiveValues: 

- (void) setTextAttributesForPositiveValues: (NSDictionary*)newAttributes;
Availability: MacOS-X 10.0.0

Sets the attributes to apply to positive values (whole string), when -attributedStringForObjectValue:withDefaultAttributes: is called. Default is none.

setThousandSeparator: 

- (void) setThousandSeparator: (NSString*)newSeparator;
Availability: MacOS-X 10.0.0

Sets thousands separator used; default is ','.

stringFromNumber: 

- (NSString*) stringFromNumber: (NSNumber*)number;
Availability: MacOS-X 10.0.0

Returns the string version of this number based on the format specified.

textAttributesForNegativeValues 

- (NSDictionary*) textAttributesForNegativeValues;
Availability: MacOS-X 10.0.0

Returns the attributes to apply to negative values (whole string), when -attributedStringForObjectValue:withDefaultAttributes: is called. Default is none.

textAttributesForPositiveValues 

- (NSDictionary*) textAttributesForPositiveValues;
Availability: MacOS-X 10.0.0

Returns the attributes to apply to positive values (whole string), when -attributedStringForObjectValue:withDefaultAttributes: is called. Default is none.

thousandSeparator 

- (NSString*) thousandSeparator;
Availability: MacOS-X 10.0.0

Returns thousands separator used; default is ','.



Instance Variables for NSNumberFormatter Class

_allowsFloats

@protected BOOL _allowsFloats;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_attributedStringForNil

@protected NSAttributedString* _attributedStringForNil;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_attributedStringForNotANumber

@protected NSAttributedString* _attributedStringForNotANumber;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_attributedStringForZero

@protected NSAttributedString* _attributedStringForZero;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_attributesForNegativeValues

@protected NSDictionary* _attributesForNegativeValues;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_attributesForPositiveValues

@protected NSDictionary* _attributesForPositiveValues;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_decimalSeparator

@protected unichar _decimalSeparator;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_hasThousandSeparators

@protected BOOL _hasThousandSeparators;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_localizesFormat

@protected BOOL _localizesFormat;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_maximum

@protected NSDecimalNumber* _maximum;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_minimum

@protected NSDecimalNumber* _minimum;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_negativeFormat

@protected NSString* _negativeFormat;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_positiveFormat

@protected NSString* _positiveFormat;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_roundingBehavior

@protected NSDecimalNumberHandler* _roundingBehavior;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_thousandSeparator

@protected unichar _thousandSeparator;
Availability: MacOS-X 10.0.0

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.





Up