Re: Creating NSDecimal
Re: Creating NSDecimal
- Subject: Re: Creating NSDecimal
- From: Ken Thomases <email@hidden>
- Date: Fri, 31 Oct 2008 03:12:03 -0500
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:
This email sent to email@hidden