• 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: NSNumberFormatter not working for me ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumberFormatter not working for me ?


  • Subject: Re: NSNumberFormatter not working for me ?
  • From: Murat Konar <email@hidden>
  • Date: Wed, 14 Apr 2010 11:04:10 -0700

Actually, setting the formatter behavior does work (it does allow you to use setFormat: to set a format string). The remaining problem is that I don't think NSNumberFormatter allows the arbitray digit-by- digit formatting of numbers that you expect.

_murat

On Apr 13, 2010, at 8:54 PM, Bill Hernandez wrote:


On Apr 13, 2010, at 8:09 PM, Murat Konar wrote:

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,

if I call:

phoneNumber = [BHUtility bhFormatNumberString:strippedNumber withFormat:@"(###) ###-####"];

run
[Switching to process 6314]
Running…
Current language: auto; currently objective-c
2010-04-13 22:48:23.398 Formatter[6314:a0f] [4625] theString = (1234567890) -
(gdb)


// +---------+---------+---------+---------+---------+--------- +---------+---------+
+ (NSString *)bhFormatNumberString:(NSString *)aNumberString withFormat:(NSString *)aFormat
{
// THIS METHOD DOES NOT WORK
[NSNumberFormatter setDefaultFormatterBehavior:NSNumberFormatterBehavior10_0];
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
// NSFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];


[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;
// +---------+---------+---------+---------+---------+--------- +---------+---------+
}


I came up with a better work-aroundthat I posted to the forum. Take a look at it, it really works very well, and is not limited to phone numbers.

Thanks a million for trying to help me...

Bill Hernandez
Plano, Texas




_______________________________________________

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


  • Follow-Ups:
    • Re: NSNumberFormatter not working for me ?
      • From: Bill Hernandez <email@hidden>
References: 
 >NSNumberFormatter not working for me ? (From: Bill Hernandez <email@hidden>)
 >Re: NSNumberFormatter not working for me ? (From: Murat Konar <email@hidden>)
 >Re: NSNumberFormatter not working for me ? (From: Bill Hernandez <email@hidden>)
 >Re: NSNumberFormatter not working for me ? (From: Murat Konar <email@hidden>)
 >Re: NSNumberFormatter not working for me ? (From: Bill Hernandez <email@hidden>)

  • Prev by Date: Re: Font Style Names for iPhone/iPad
  • Next by Date: Playing DVD Programmatically?
  • Previous by thread: Re: NSNumberFormatter not working for me ?
  • Next by thread: Re: NSNumberFormatter not working for me ?
  • Index(es):
    • Date
    • Thread