Re: Problem displaying correct double values in NSTextField (Cocoa)
Re: Problem displaying correct double values in NSTextField (Cocoa)
- Subject: Re: Problem displaying correct double values in NSTextField (Cocoa)
- From: Michael Gersten <email@hidden>
- Date: Fri, 08 Mar 2002 12:14:16 -0800
I'm sure others will disagree (this came up about a month ago ...
amazing what perspective you get by playing catch-up with messages),
but basically NSTextField will truncate, rather than round.
Beyond that, you're looking at the float/double inexactness problem.
Michael.
p.s. Judging by the number of zero's, it looks like the 8.540000
answer is a float, not a double. Perhaps this particular error only
shows up on the extra percision? (Hey, wasn't it the extra percision
of the pentium that caused intel's math error?)
John McGruer wrote:
>
>
There seems to be a bug in NSTextField (Cocoa) that displays double values
>
incorrectly. Below is a simplified version of code I'm writing. Basically
>
I'm adding two double values (5.54 + 3.0). If I then display the result in
>
the console (Project Builder) is gives 8.540000 (ok) but displaying the
>
answer in an NSTextField gives 8.53999999999 (not ok!!). I don't want to
>
have to format the answer. What's going on?
>
>
#import "MyController.h"
>
>
@implementation MyController
>
>
- (IBAction)add:(id)sender
>
{
>
double num3;
>
double num1 = 5.54;
>
double num2 = 3.0;
>
>
num3 = (num1 + num2);
>
>
NSLog(@"answer = %lf", num3); //gives "answer = 8.540000"
>
>
[answerField setDoubleValue:num3]; //gives "8.539999999999" !!!
>
}
>
>
@end
>
_______________________________________________
>
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.
_______________________________________________
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.