Re: Array controllers in code?
Re: Array controllers in code?
- Subject: Re: Array controllers in code?
- From: Quincey Morris <email@hidden>
- Date: Thu, 22 Jul 2010 13:15:41 -0700
On Jul 22, 2010, at 13:03, Amy Gibbs wrote:
> I've tried declaring all sorts of things trying to get it to work :D float, decimal, (the entity properties are decimal in the datamodel), NSNumber, but I still get the error: invalid operands to binary /
>
> I assume I can't use int as the figures aren't integers, I only need it to 2 decimal places (for currency).
You're missing the distinction between an object and a scalar value.
'valueForKey' returns an object (presumably a NSNumber), but '/' needs scalars. So, you need something along this line:
NSNumber* price = [Product valueForKey:@"UOMcost"];
NSNumber* uom = [Product valueForKey:@"purchaseUOM"];
double result = [uom doubleValue] / [price doubleValue];
NSNumber* cost = [NSNumber numberWithDouble: result];
[Product setValue: cost for Key: ...];
Incidentally, if you're dealing with currency, it's better to use integers (the number of cents, rather than the number of dollars, essentially) rather than floating point.
_______________________________________________
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