• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Array controllers in code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Array controllers in code?
      • From: Chris Hanson <email@hidden>
References: 
 >Array controllers in code? (From: Amy Gibbs <email@hidden>)
 >Re: Array controllers in code? (From: Jack Nutting <email@hidden>)
 >Re: Array controllers in code? (From: Amy Gibbs <email@hidden>)
 >Re: Array controllers in code? (From: Ken Thomases <email@hidden>)
 >Re: Array controllers in code? (From: Amy Gibbs <email@hidden>)

  • Prev by Date: Re: Array controllers in code?
  • Next by Date: Re: Deselect keyboard focus of an NSMatrix cell
  • Previous by thread: Re: Array controllers in code?
  • Next by thread: Re: Array controllers in code?
  • Index(es):
    • Date
    • Thread