Up
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.
- 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
- (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
.
- (
NSAttributedString*)
attributedStringForNil;
Availability: MacOS-X 10.0.0
Returns the exact attributed string used for
nil
values. By default this is an empty
string.
- (
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.
- (
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.
- (
NSString*)
decimalSeparator;
Availability: MacOS-X 10.0.0
Returns thousands separator used; default is '.'.
- (
NSString*)
format;
Availability: MacOS-X 10.0.0
Returns the format string this instance was
initialized with.
- (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.)
- (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.
- (
NSDecimalNumber*)
maximum;
Availability: MacOS-X 10.0.0
Returns maximum value that will be accepted as
valid in number parsing. Default is none.
- (
NSDecimalNumber*)
minimum;
Availability: MacOS-X 10.0.0
Returns minimum value that will be accepted as
valid in number parsing. Default is none.
- (
NSString*)
negativeFormat;
Availability: MacOS-X 10.0.0
Returns format used for negative numbers.
- (
NSNumber*)
numberFromString: (
NSString*)string;
Availability: MacOS-X 10.0.0
Returns the number for this string.
- (
NSString*)
positiveFormat;
Availability: MacOS-X 10.0.0
Returns format used for positive numbers.
- (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
.
- (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.
- (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.
- (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.
- (void)
setDecimalSeparator: (
NSString*)newSeparator;
Availability: MacOS-X 10.0.0
Sets thousands separator used; default is '.'.
- (void)
setFormat: (
NSString*)aFormat;
Availability: MacOS-X 10.0.0
Sets format string. See class description for more
information.
- (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.)
- (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.
- (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.
- (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.
- (void)
setNegativeFormat: (
NSString*)aFormat;
Availability: MacOS-X 10.0.0
Sets format used for negative numbers. See class
description for more information.
- (void)
setPositiveFormat: (
NSString*)aFormat;
Availability: MacOS-X 10.0.0
Sets format used for positive numbers. See class
description for more information.
- (void)
setTextAttributesForNegativeValues: (
NSDictionary*)newAttributes;
Availability: MacOS-X 10.0.0
- (void)
setTextAttributesForPositiveValues: (
NSDictionary*)newAttributes;
Availability: MacOS-X 10.0.0
- (void)
setThousandSeparator: (
NSString*)newSeparator;
Availability: MacOS-X 10.0.0
Sets thousands separator used; default is ','.
- (
NSString*)
stringFromNumber: (
NSNumber*)number;
Availability: MacOS-X 10.0.0
Returns the string version of this
number based on the format specified.
- (
NSDictionary*)
textAttributesForNegativeValues;
Availability: MacOS-X 10.0.0
- (
NSDictionary*)
textAttributesForPositiveValues;
Availability: MacOS-X 10.0.0
- (
NSString*)
thousandSeparator;
Availability: MacOS-X 10.0.0
Returns thousands separator used; default is ','.
Instance Variables for NSNumberFormatter Class
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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.
@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