• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem displaying correct double values in NSTextField (Cocoa)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Problem displaying correct double values in NSTextField (Cocoa)
      • From: Michael Gersten <email@hidden>
    • Re: Problem displaying correct double values in NSTextField (Cocoa)
      • From: Markus Hitter <email@hidden>
  • Prev by Date: Re: URL o' my dreams
  • Next by Date: Re: Bundles as plugins - Got it
  • Previous by thread: writeInBackgroundAndNotify?
  • Next by thread: Re: Problem displaying correct double values in NSTextField (Cocoa)
  • Index(es):
    • Date
    • Thread