NSDecimalNumber

NSDecimalNumber Mac OS X 10.0

This subclass of NSNumber provides an object-oriented wrapper for performing base-10 arithmetic operations. Instances of NSDecimalNumber are created with a string such as "10.2e4" using decimalNumberWithString:, or by specifying the mantissa, exponent, and whether or not it is negative in the method decimalNumberWith-Mantissa:exponent:isNegative:.

Arithmetic operations are performed on two decimal number objects using methods such as decimalNumberByAdding:, decimalNumberByMultiplying:, and so forth. The value of the decimal number can be accessed as a double by sending a doubleValue message to the object.

figs/cocn_1326.gif

@interface NSDecimalNumber : NSNumber
 // Initializers
   - (id)initWithDecimal:(NSDecimal)dcm;
   - (id)initWithMantissa:(unsigned long long)mantissa exponent:(short)exponent isNegative:(BOOL)flag;
   - (id)initWithString:(NSString *)numberValue;
   - (id)initWithString:(NSString *)numberValue locale:(NSDictionary *)locale;
 // Class Methods
   + (NSDecimalNumber *)decimalNumberWithDecimal:(NSDecimal)dcm;
   + (NSDecimalNumber *)decimalNumberWithMantissa:(unsigned long long)mantissa
        exponent:(short)exponent isNegative:(BOOL)flag;
   + (NSDecimalNumber *)decimalNumberWithString:(NSString *)numberValue;
   + (NSDecimalNumber *)decimalNumberWithString:(NSString *)numberValue locale:(NSDictionary *)locale;
   + (id <NSDecimalNumberBehaviors>)defaultBehavior;
   + (NSDecimalNumber *)maximumDecimalNumber;
   + (NSDecimalNumber *)minimumDecimalNumber;
   + (NSDecimalNumber *)notANumber;
   + (NSDecimalNumber *)one;
   + (void)setDefaultBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   + (NSDecimalNumber *)zero;
 // Instance Methods
   - (NSComparisonResult)compare:(NSNumber *)decimalNumber;
   - (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber;
   - (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber          
        withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber;
   - (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber      
        withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber;
   - (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber   
        withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power;
   - (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power
        withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberByRaisingToPower:(unsigned)power;
   - (NSDecimalNumber *)decimalNumberByRaisingToPower:(unsigned)power
     withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberByRoundingAccordingToBehavior:
        (id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimalNumber *)decimalNumberBySubtracting:(NSDecimalNumber *)decimalNumber;
   - (NSDecimalNumber *)decimalNumberBySubtracting:(NSDecimalNumber *)decimalNumber    
         withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
   - (NSDecimal)decimalValue;
   - (NSString *)descriptionWithLocale:(NSDictionary *)locale;
   - (double)doubleValue;
   - (const char *)objCType;



    Part II: API Quick Reference
    Chapter 13. Foundation Classes