Re: flummoxed by math failure
Re: flummoxed by math failure
- Subject: Re: flummoxed by math failure
- From: Dean Tresner <email@hidden>
- Date: Wed, 23 Jul 2003 17:08:46 -0600
Karl,
By trivial accessor, I meant, e.g.
- (NSDecimalNumber *)rate {
return rate;
}
The member variables rate and hours are indeed declared to be of type
NSDecimalNumber*. But I think you may have just pointed me in the right
direction. The objects of which this code snippet is a part are model
objects which populate an NSTableView and can be edited via
key-value-coding (referred to here as item):
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn row:(int)row {
...
[item takeValue:object forKey:[tableColumn identifier]];
...
}
Which is the mechanism I used to generate this test case. I have
standard NSNumberFormatters on the table columns for rate and hours and
I *give* the table cells NSDecimalNumbers, but they must still be
handing me back string values. I will check it out.
Thanks,
Dean
On Wednesday, Jul 23, 2003, at 16:25 America/Denver, Karl Kraft wrote:
In coding, nothing is ever trivial. When you come across what appears
to be a broken compiler or code that doesn't compute correctly, the
problem is usually occurring far before the part that is generating
the output.
Your problem is that rate is not a NSDecimalNumber. It is most likely
an NSString.
Did you declare it as id or NSDecimalNumber* ?
How did you assign the value to rate?
Sample code to demonstrate:
#import <Cocoa/Cocoa.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *p =[[NSAutoreleasePool alloc] init];
id hours=[NSDecimalNumber decimalNumberWithString:@"1"];
id rate1 =[NSDecimalNumber decimalNumberWithString:@"100"];
id rate2 =@"100";
NSLog(@"%@ X %@ = %@", hours, rate1 , [hours
decimalNumberByMultiplyingBy:rate1]);
NSLog(@"%@ X %@ = %@", hours, rate2 , [hours
decimalNumberByMultiplyingBy:rate2]);
[p release];
return 0;
}
Sample Output:
2003-07-23 17:23:15.693 nsdf[12908] 1 X 100 = 100
2003-07-23 17:23:15.709 nsdf[12908] 1 X 100 = 0
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.