Creating a Decimal Number Handler

+ defaultDecimalNumberHandler

Returns the default instance of NSDecimalNumberHandler.

Example

NSDecimalNumberHandler *handler = [NSDecimalNumberHandler defaultDecimalNumberHandler];
NSLog(@"%d",[handler scale]);
		

Output

2014-04-12 04:57:02.699 iOS-Tutorial[1293:a0b] 32767
		

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

Returns an NSDecimalNumberHandler object with customized behavior.

Example

NSDecimalNumberHandler *numberHandler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:YES raiseOnOverflow:YES raiseOnUnderflow:YES raiseOnDivideByZero:YES];
NSLog(@"%d",[numberHandler scale]);
NSLog(@"%d",[numberHandler roundingMode]);
		

Output

2014-04-12 05:00:39.819 iOS-Tutorial[1310:a0b] 2
2014-04-12 05:00:39.820 iOS-Tutorial[1310:a0b] 1
		

Initializing a Decimal Number Handler

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

Returns an NSDecimalNumberHandler object initialized so it behaves as specified by the methodÂ’s arguments.

Example

NSDecimalNumberHandler *numberHandler = [[NSDecimalNumberHandler alloc ]initWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:YES raiseOnOverflow:YES raiseOnUnderflow:YES raiseOnDivideByZero:YES];
NSLog(@"%d",[numberHandler scale]);
NSLog(@"%d",[numberHandler roundingMode]);
		

Output

2014-04-12 05:01:25.726 iOS-Tutorial[1322:a0b] 2
2014-04-12 05:01:25.727 iOS-Tutorial[1322:a0b] 1
		

Advertisements