Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating NSDecimal



On Oct 31, 2008, at 1:24 AM, Andrew Farmer wrote:

On 30 Oct 08, at 23:18, Graham Cox wrote:
On 31 Oct 2008, at 5:08 pm, HAMILTON, Steven wrote:
Hi folks,
Can someone tell me how I create an NSDecimal? The C struct one, not the ObjC NSDecimalNumber. For performance and simplicity I'd rather use the C interface but for the life of me I can't find out how to actually create one of these and assign a value to it.


//Declare
NSDecimal *decimal;
//assign? Surely its not as simple as this?
decimal = 16.75

It does seem weird that there's no way to create a NSDecimal! I'm pretty sure simple assignment won't work.

It definitely won't. NSDecimal is a structure something like a floating-point value.


The only way I can see is something like this:

NSDecimal decimal = [[NSDecimalNumber decimalNumberWithString:@"16.75"] decimalValue];

maybe that helps?

The other one I was able to find was NSScanner's -scanDecimal: (NSDecimal *) method. It's still really weird that there's no method to initialize one from (say) an integer, though.

NSNumber has a -decimalValue method, which is probably much simpler to use than either of the string-based methods (NSScanner or NSDecimalNumber).


Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Creating NSDecimal (From: "HAMILTON, Steven" <email@hidden>)
 >Re: Creating NSDecimal (From: Graham Cox <email@hidden>)
 >Re: Creating NSDecimal (From: Andrew Farmer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.