If you don't explicitly set a formatter behavior, you are probably getting the newest behavior "NSNumberFormatterBehavior10_4", and - setFormat: does require the older "NSNumberFormatterBehavior10_0" behavior. That's why your string is being returned unchanged. As far as the formatter is concerned, you have not set a format string.

Note also that in your most recently posted code, you set the default behavior for the class *after* you allocate an instance. You should either set the default behavior before creating an instance, or set the behavior on the instance itself.

_murat



On Apr 13, 2010, at 4:37 PM, Bill Hernandez wrote:


On Apr 13, 2010, at 5:50 PM, Murat Konar wrote:

For one thing, the docs say that -setFormat: is for use with formatters using NSNumberFormatterBehavior10_0 behavior.

Have you set the formatters behavior?


murat,

No, just the way the code showed. Here's from the docs :

-- From what I can see it should work out or the box ???

NSNumberFormatterBehavior10_0
The number-formatter behavior as it existed prior to Mac OS X v10.4.
Available in Mac OS X v10.4 and later.

I added : [NSNumberFormatter setDefaultFormatterBehavior:NSNumberFormatterBehavior10_0];
but it didn't help...

// +---------+---------+---------+---------+---------+--------- +---------+---------+ + (NSString *)bhFormatNumberString:(NSString *)aNumberString withFormat:(NSString *)aFormat
{
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];

[NSNumberFormatter setDefaultFormatterBehavior:NSNumberFormatterBehavior10_0]; [numberFormatter setFormat:aFormat]; // specify just positive values format
        
        NSInteger theInt = [aNumberString intValue];
        NSNumber *theNum = [NSNumber numberWithInt:theInt];
NSString *theString = (NSString *)[numberFormatter stringFromNumber:theNum];
        NSLog(@"[4625] theString = %@", theString);
        
        return theString;
// +---------+---------+---------+---------+---------+--------- +---------+---------+
}


Bill Hernandez
Plano, Texas



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to