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 (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to