• 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
Lenient NSNumberFormatters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lenient NSNumberFormatters


  • Subject: Lenient NSNumberFormatters
  • From: Frank Illenberger <email@hidden>
  • Date: Thu, 21 Aug 2008 09:04:16 +0200

Hi there,

has anybody successfully used NSNumberFormatter's new setLenient: feature that was introduced with 10.5 together with one of the common number styles like currency or percent? As usual, I want the formatter to show a currency or percent symbol when turning numbers into strings but to be forgiving of omitted symbols when converting a user's string input into numbers.

The following code

	NSNumberFormatter *percentFormatter = [[NSNumberFormatter alloc] init];
	percentFormatter.formatterBehavior = NSNumberFormatterBehavior10_4;
	percentFormatter.numberStyle = NSNumberFormatterPercentStyle;
	[percentFormatter setLenient:YES];
	NSLog(@"%@", [percentFormatter numberFromString:@"10"]);

outputs "(null)".  The same happens with the currency style.

Is there any way to get a lenient behavior from NSNumberFormatter without having to subclass it?

Cheers

 Frank


_______________________________________________

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: Source List groups shifted down in NSOutlineView
  • Next by Date: warning: initialization makes integer from pointer without a cast
  • Previous by thread: Re: Source List groups shifted down in NSOutlineView
  • Next by thread: warning: initialization makes integer from pointer without a cast
  • Index(es):
    • Date
    • Thread