Problem displaying correct double values in NSTextField (Cocoa)
Problem displaying correct double values in NSTextField (Cocoa)
- Subject: Problem displaying correct double values in NSTextField (Cocoa)
- From: John McGruer <email@hidden>
- Date: Sun, 03 Mar 2002 13:56:52 +0800
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.