Equivalent functionality to the
NSDecimalNumber class may be accessed
through functions, mostly named
NSDecimalXXX, e.g.,
NSDecimalMin()
. Both the class and the functions use a structure
called NSDecimal.
Note that instances of NSDecimalNumber
are immutable.
New instance from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy... methods will return
a result constrained by the current
scale. Number format is parsed
according to current default locale.
New instance from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy... methods will return
a result constrained by the current
scale. Number format is parsed
according to given locale.
Initialize from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy... methods will return
a result constrained by the current
scale. Number format is parsed
according to current default locale.
Initialize from string. Arbitrary precision is
preserved, though calling one of the
decimalNumberBy... methods will return
a result constrained by the current
scale. Number format is parsed
according to given locale.
Returns the Objective-C type (
@encode(...) compatible) of the data
contained NSDecimalNumber, which is
by convention "d" (for double), even
though this is not strictly accurate.
A utility class adopting
<NSDecimalNumberBehaviors>
protocol. Can be used to control
NSDecimalNumber
rounding and exception-handling behavior, by
passing an instance as an argument to any
NSDecimalNumber
method ending with ...Behavior:.
Constructor setting all behavior. (For more
precise control over error handling, create your
own class implementing the
<NSDecimalNumberBehaviors>
protocol.)
Provides an instance implementing the default
behavior for the
NSDecimalNumber
class. 38 decimal digits, rounded to closest
return value (NSRoundPlain).
Exceptions raised on overflow, underflow, and
divide by zero.
Initializer setting all behavior. (For more
precise control over error handling, create your
own class implementing the
<NSDecimalNumberBehaviors>
protocol.)
Instance Variables for NSDecimalNumberHandler Class
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.
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.
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.
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.
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.
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.
Obtaining an NSDecimalNumber version of an
ordinary NSNumber. Returns an NSDecimal
representation of the number. Float and
double values may not be
converted exactly
This protocol encapsulates information about how an
NSDecimalNumber
should round and process exceptions. Usually you can
just create objects of the
NSDecimalNumberHandler
class, which implements this protocol, but if you
don't want to use that class you can create your
own implementing it.
Specifies behavior when, in the course of
applying method to
leftOperand and rightOperand,
an
NSDecimalNumber
instance encounters given error.
error has four possible constant
values:
NSCalculationLossOfPrecision
The number can't be represented in 38 significant
digits.
NSCalculationOverflow
The number is too large to represent.
NSCalculationUnderflow
The number is too small to represent.
NSCalculationDivideByZero
The caller tried to divide by 0.
Behavior on error can be one of the
following:
Raise an exception.
Return nil. The calling
method will return its value as
though no error had occurred. If
error is
NSCalculationLossOfPrecision,
method will return an imprecise
value, constrained to 38 significant digits.
If error is
NSCalculationUnderflow or
NSCalculationOverflow,
method will return
NSDecimalNumber 's
notANumber. You shouldn't return
nil if error is
NSDivideByZero.
Correct the error and return a
valid NSDecimalNumber. The calling
method will use this as its own
return value.
Specifies the precision of the values returned by
NSDecimalNumber
's decimalNumberBy... methods, in terms
of the number of digits allowed after the decimal
point. This can be negative, implying that the
precision should be, e.g., 100's, 1000's, etc..
For unlimited precision, set to
NSDecimalNoScale.