• 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
doubleValue (for an NSString)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

doubleValue (for an NSString)


  • Subject: doubleValue (for an NSString)
  • From: Boyd Collier <email@hidden>
  • Date: Fri, 21 Mar 2008 18:54:34 -0700

First, thanks to everyone who suggested ways to handle this. Next, an admission of guilt for faulty memory; mine, not my Mac's: in poking around, I discovered that I'd asked pretty much the same question (for ints) nearly 2 years ago and had gotten similar answers. My apologies.

I've decided to use a scanner, and, as a couple of you said, it's really rather simple. But I was concerned about whether using something like

	[[NSScanner scannerWithString:aString] scanDouble:&distance];

when, in some situations, I will be scanning for potentially thousands of values within a loop, and so I presumed that this would cause an equal number of scanners to accumulate in the default autorelease pool. Is that correct? So I tried

	NSScanner *tempScanner = [[NSScanner alloc] initWithString:aString];
	[tempScanner scanDouble:&distance];
	[tempScanner release];

in a loop, wondering if all the allocations and releases would slow things down. The result was that scanning for 10000 values took only about 8 milliseconds on my 2.8 GHz iMac, which is plenty fast enough for my purposes.

Any further comments, even ones telling me that I should take up knitting instead of programming, are welcome.

Boyd


On Mar 20, 2008, at 4:13 PM, Boyd Collier wrote:

According to Apple's documents, the selector doubleValue returns 0.0 if the instance of an NSString that is the receiver "doesn’t begin with a valid text representation of a floating-point number." Is there a simple way to distinguish between the string 0.0, which shouldn't be considered illegitimate for my purposes, and the string (for example) X0.0 other than writing extra lines of code to distinguish one case from the other? I know I could use a scanner, but perhaps there's something simple that I'm overlooking.

Boyd_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: View with sliding rearranging thumbnails
  • Next by Date: Re: View with sliding rearranging thumbnails
  • Previous by thread: Re: doubleValue (for an NSString)
  • Next by thread: Creating custom sheets
  • Index(es):
    • Date
    • Thread