NaN (Not a Number) Error using Bindings
NaN (Not a Number) Error using Bindings
- Subject: NaN (Not a Number) Error using Bindings
- From: "J. Scott Anderson" <email@hidden>
- Date: Tue, 4 Jan 2005 12:27:00 -0600
I am running a simple test for using Bindings with tables and math. All
if it runs very well except for one little problem the division of one
number by another. I have had other Cocoa programmers take a look at it
and no one can figure out why it doesn't work. So, it is either a bug
or we are all missing something very obvious. Here are the details:
Header file shows the following:
***********************************************
{
double quoteExtendedRetail;
double quoteExtendedCost;
double quoteExtendedPrice;
double quoteShipping;
}
- (double)quoteProfit;
- (double)quoteProfitMargin;
- (double)quoteSubTotal;
- (double)quoteTax;
- (double)quoteTotal;
***********************************************
As you can see, just simple stuff. The implementation file is just as
simple. I based this off the Currency Converter example Apple uses to
expose new users to Cocoa Bindings. The implementation file shows the
following:
***********************************************
- (double)quoteProfit
{
return (double)(quoteExtendedPrice - quoteExtendedCost);
}
- (double)quoteProfitMargin // TODO: Fix this. I get an "NaN"
(Not a Number) result in compiled application.
{
return (double)(quoteExtendedCost / quoteExtendedPrice);
}
- (double)quoteSubTotal
{
return (double)(quoteExtendedPrice + quoteShipping);
}
- (double)quoteTax
{
return (double)(quoteExtendedPrice * .0875); // TODO: Replace
explict tax rate with user setting.
}
- (double)quoteTotal
{
return (double)(quoteExtendedPrice + quoteShipping +
(quoteExtendedPrice * .0875));
}
+ (void)initialize
{
[STQuoteTotals setKeys:
[NSArray arrayWithObjects:@"quoteExtendedPrice",
@"quoteExtendedCost", nil]
triggerChangeNotificationsForDependentKey:@"quoteProfit"];
[STQuoteTotals setKeys:
[NSArray arrayWithObjects:@"quoteExtendedCost",
@"quoteExtendedPrice", nil]
triggerChangeNotificationsForDependentKey:@"quoteProfitMargin"];
[STQuoteTotals setKeys:
[NSArray arrayWithObjects:@"quoteExtendedPrice", @"quoteShipping",
nil]
triggerChangeNotificationsForDependentKey:@"quoteSubTotal"];
[STQuoteTotals setKeys:
[NSArray arrayWithObjects:@"quoteExtendedPrice", nil]
triggerChangeNotificationsForDependentKey:@"quoteTax"];
[STQuoteTotals setKeys:
[NSArray arrayWithObjects:@"quoteExtendedPrice", @"quoteShipping",
@"quoteTax", nil]
triggerChangeNotificationsForDependentKey:@"quoteTotal"];
}
***********************************************
As stated above, everything works except for the simple profit margin
calculation. It should work but does not. I get that "NaN" result
displayed. Any suggestions for what we are doing wrong?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden