Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSDecimalNumber.h |
NSDecimalNumberHandler
is a class that adopts the NSDecimalNumberBehaviors
protocol. This class allows you to set the way an NSDecimalNumber
object 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 ...Behavior:
. If you don’t think you need special behavior, you probably don’t need this class—it is likely that NSDecimalNumber
's default behavior will suit your needs.
For more information, see the NSDecimalNumberBehaviors protocol specification.
+ defaultDecimalNumberHandler
+ decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:
Returns an NSDecimalNumberHandler
object with customized behavior.
+ (id)decimalNumberHandlerWithRoundingMode:(NSRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)raiseOnExactness raiseOnOverflow:(BOOL)raiseOnOverflow raiseOnUnderflow:(BOOL)raiseOnUnderflow raiseOnDivideByZero:(BOOL)raiseOnDivideByZero
The rounding mode to use. There are four possible values: NSRoundUp
, NSRoundDown
, NSRoundPlain
, and NSRoundBankers
.
The number of digits a rounded value should have after its decimal point.
If YES
, in the event of an exactness error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method.
If YES
, in the event of an overflow error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
If YES
, in the event of an underflow error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
If YES
, in the event of a divide by zero error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
An NSDecimalNumberHandler
object with customized behavior.
See the NSDecimalNumberBehaviors protocol specification for a complete explanation of the possible behaviors.
NSDecimalNumber.h
Returns the default instance of NSDecimalNumberHandler
.
+ (id)defaultDecimalNumberHandler
The default instance of NSDecimalNumberHandler
.
This default decimal number handler 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
object tries to divide by 0
or when its NSDecimalNumber
object produces a number too big or too small to be represented.
NSDecimalNumber.h
Returns an NSDecimalNumberHandler
object initialized so it behaves as specified by the method’s arguments.
- (id)initWithRoundingMode:(NSRoundingMode)roundingMode scale:(short)scale raiseOnExactness:(BOOL)raiseOnExactness raiseOnOverflow:(BOOL)raiseOnOverflow raiseOnUnderflow:(BOOL)raiseOnUnderflow raiseOnDivideByZero:(BOOL)raiseOnDivideByZero
The rounding mode to use. There are four possible values: NSRoundUp
, NSRoundDown
, NSRoundPlain
, and NSRoundBankers
.
The number of digits a rounded value should have after its decimal point.
If YES
, in the event of an exactness error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method.
If YES
, in the event of an overflow error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
If YES
, in the event of an underflow error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
If YES
, in the event of a divide by zero error the handler will raise an exception, otherwise it will ignore the error and return control to the calling method
An initialized NSDecimalNumberHandler
object initialized with customized behavior. The returned object might be different than the original receiver.
See the NSDecimalNumberBehaviors protocol specification for a complete explanation of the possible behaviors.
NSDecimalNumber.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-30)