O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSDecimalNumber — Mac OS X 10.0

Synopsis

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.

image with no caption

@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>) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required