• 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
Strange behaviour of scanFloat
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange behaviour of scanFloat


  • Subject: Strange behaviour of scanFloat
  • From: Marco Michieli <email@hidden>
  • Date: Sun, 6 Nov 2005 01:51:56 +0100

I'm using scanFloat to read float numbers from a text file, but I realized that for example the string "273.4501" is converted to the value "273.450104" and not "273.450100".

What's going on?

Here below the code and the correspondent log:



- (IBAction)test:(id)sender
{
	NSScanner *theScanner;
	NSString *scanString = @"237.4501";
	float floatValue;
    theScanner = [NSScanner scannerWithString:scanString];
	if ([theScanner scanFloat:&floatValue]) {
		NSLog(@"scanString:%@  scanned value:%f", scanString, floatValue);
	} else {
		NSLog(@"Scan Error");
	}
}


2005-11-06 01:33:39.556 Test[622] scanString:237.4501 scanned value: 237.450104




Thanks for your help.


Best regards

Marco Michieli
_______________________________________________
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


  • Follow-Ups:
    • Re: Strange behaviour of scanFloat
      • From: Ryan Britton <email@hidden>
  • Prev by Date: Re: Making menu bar application's window key
  • Next by Date: Core Data Predicates with Relationships and Objects
  • Previous by thread: sheets and undo
  • Next by thread: Re: Strange behaviour of scanFloat
  • Index(es):
    • Date
    • Thread