• 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
Re: API to convert string to number?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: API to convert string to number?


  • Subject: Re: API to convert string to number?
  • From: "E. Wing" <email@hidden>
  • Date: Tue, 27 Feb 2007 17:55:21 -0800

   If you read the docs as has been suggested, you'll see that
NSNumberFormatter (in 10.4) has a method -numberFromString: which,
according to the docs, "Returns an NSNumber object created by parsing
a given string."


So I relooked at NSNumberFormatter. It handles the thousands separator correctly, but it fails to handle exponent characters. (strtod and NSScanner handle the exponent but fail with the thousands separator)

I tried using the method setExponentSymbol, but it has no effect. In
fact, if I call exponentSymbol right after the set to check the value,
I get nil. So what did I screw up now?


float converted_value; NSNumberFormatter* number_formatter = [[[NSNumberFormatter alloc] init] autorelease]; [number_formatter setExponentSymbol:@"e"]; NSLog(@"exponentSymbol: %@", [number_formatter exponentSymbol]);

NSNumber* ns_number = [number_formatter numberFromString:user_string];
if(nil == ns_number)
{
   NSLog(@"numberFromString failed");
   return;
}
converted_value = [ns_number floatValue];


Thanks, Eric _______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >API to convert string to number? (From: "E. Wing" <email@hidden>)
 >Re: API to convert string to number? (From: "Shawn Erickson" <email@hidden>)
 >Re: API to convert string to number? (From: "E. Wing" <email@hidden>)
 >Re: API to convert string to number? (From: "I. Savant" <email@hidden>)
 >Re: API to convert string to number? (From: "E. Wing" <email@hidden>)
 >Re: API to convert string to number? (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: An idea about desktop amusing
  • Next by Date: NSTextView Containers and Coordinates
  • Previous by thread: Re: API to convert string to number?
  • Next by thread: question about null
  • Index(es):
    • Date
    • Thread