Lenient NSNumberFormatters
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