PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSDecimalNumberHandler


Inherits from:
NSObject
Conforms to:
NSDecimalNumberBehaviors
NSObject (NSObject)
Declared in:
Foundation/NSDecimalNumber.h




Class Description


NSDecimalNumberHandler is a class that adopts the NSDecimalNumberBehaviors protocol. This class allows you to set the way an NSDecimalNumber rounds off and handles errors, without having to create a custom class.

You can use an instance of this class as an argument to any of the NSDecimalNumber methods that end with the word ...Behavior:. If you don't think you need special behavior, you probably don't need this class. The odds are that NSDecimalNumber's default behavior will suit your needs.

For more information, see the NSDecimalNumberBehaviors protocol specification.




Adopted Protocols


NSDecimalNumberBehaviors
- roundingMode
- scale
- exceptionDuringOperation:error:leftOperand:rightOperand:


Method Types


Creating and initializing an NSDecimalNumberHandler
+ defaultDecimalNumberHandler
+ decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:
Initializing an already-created NSDecimalNumberHandler
- initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:


Class Methods



defaultDecimalNumberHandler

+ (id)defaultDecimalNumberHandler

Creates and returns the default instance of NSDecimalNumberHandler.

This instance rounds to the closest possible return value. It assumes your need for precision does not exceed 38 significant digits, and it raises an exception when its NSDecimalNumber tries to divide by zero, or when its NSDecimalNumber produces a number is too big or too small to be represented.



decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:

+ (id)decimalNumberHandlerWithRoundingMode:(NSRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)raiseOnExactness raiseOnOverflow:(BOOL)raiseOnOverflow raiseOnUnderflow:(BOOL)raiseOnUnderflow raiseOnDivideByZero:(BOOL)raiseOnDivideByZero

Creates and returns an NSDecimalNumberHandler with customized behavior.

scale and roundingMode affect the way the NSDecimalNumberHandler's NSDecimalNumber rounds off its return value. scale sets the number of digits a rounded value should have after its decimal point. roundingMode sets the rule by which NSDecimalNumbers are rounded off. roundingMode has four possiblevalues: NSRoundUp, NSRoundDown, NSRoundPlain, and NSRoundBankers.

The raiseOn... arguments determine whether the NSDecimalNumberHandler will raise an exception when its NSDecimalNumber notifies it of a certain kind of calculation error. If a raiseOn... argument is YES, NSDecimalNumberHandler will raise an exception; if a raiseOn... argument is NO, NSDecimalNumber will ignore the error, and return control to the calling method.

See the NSDecimalNumberBehaviors protocol specification for a complete explanation of these possible behaviors.




Instance Methods



initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:

- (id)initWithRoundingMode:(NSRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)raiseOnExactness raiseOnOverflow:(BOOL)raiseOnOverflow raiseOnUnderflow:(BOOL)raiseOnUnderflow raiseOnDivideByZero:(BOOL)raiseOnDivideByZero

Initializes a previously-allocated NSDecimalNumberHandler so it behaves as specified by the method's arguments. For an explanation of these arguments, see the decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero: class method.

Returns self.




Table of Contents