Documentation Archive Developer
Search

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 does not round numbers off. It assumes that 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 that is too big or 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 that 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 spectification 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 that 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.

Copyright © 1997, Apple Computer, Inc. All rights reserved.