Re: Array controllers in code?
Re: Array controllers in code?
- Subject: Re: Array controllers in code?
- From: Amy Gibbs <email@hidden>
- Date: Fri, 23 Jul 2010 13:19:05 +0100
this did it! Thank You, I think that was the problem, the values were
NSDecimalNumber not NSNumber! anyway, it works so fingers crossed I
can get this little app finished soon Yay :)
just for reference, my final code:
/** Calculate Product Cost */
- (IBAction)calcCost:(id)sender;
{
NSObject *Product;
NSDecimalNumber *price, *uom, *cost;
Product = [[Products selectedObjects] objectAtIndex:0];
price = [Product valueForKey:@"UOMcost"];
NSLog(@"Price is %@", price);
uom = [Product valueForKey:@"purchaseUOM"];
NSLog(@"UOM is %@", uom);
cost = [price decimalNumberByDividingBy:uom];
//cost = uom/price;
NSLog(@"Cost is %@", cost);
[Product setValue:cost forKey:@"cost"];
}
I put in the price and uom in the interface, click the button and it
works out the price and saves it to the datastore.
Many Thanks for all your help, still looking for a good objective-c
reference as nothing in the local bookshops, going to have to be good
old Amazon I think,
Thank You again for all your help time and patience everyone,
Amy
On 23 Jul 2010, at 12:01PM, Chris Hanson wrote:
On Jul 22, 2010, at 1:15 PM, Quincey Morris <email@hidden
> wrote:
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.
Actually, the OP has said that her data model has these attributes
as decimal; this means the values will be instances of
NSDecimalNumber.
This is correct, and is how you should generally work with currency
values in Cocoa (rather than as integers) because it allows you
control over rounding behavior, which can be very important in
financial calculations.
NSDecimalNumber also has calculation methods to use, so the OP
doesn't need to use +-*/%, but rather the equivalent methods on
NSDecimalNumber instances.
-- Chris
_______________________________________________
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
_______________________________________________
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