• 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: Greg Guerin <email@hidden>
  • Date: Wed, 14 Apr 2010 15:25:34 -0700

Bill Hernandez wrote:

I've worked with lots of number formatters over the years, and that is what they do, format numbers into strings, any kind of string...

I looked at the header file for NSNumberFormatter, and there seem to be 9,000,000+ methods, it is amazing. Buried in there, there has to be a simple way to format a string, that I am overlooking ?

If you look the simple formatter I wrote up last night, it will format a string digits any way imaginable.

Your code formats strings (more specifically, characters in strings). It does not format numbers, as such.


By "number" I mean a binary numeric value (floating-point or integer), or possibly NSNumber or NSDecimalNumber.

All your "number" parameters are actually of the NSString* type, not of a numeric type. The fact that the string contains digits is incidental. In a sense, converting a numeric value to NSString* is already a "formatting" operation, or at least a conversion operation.

Your code would work just as well if you passed it an alphabetic string, or one containing punctuation marks.

strippedNumber = @"SueMeTomorrow"
format = @"Social Security : ###-##-###"
result = @"Social Security : Sue-Me-Tom"

I'm not saying the digit-string isn't relevant to what you're doing, only that what you seem to think of as a number is, in fact, a string that happens to contain a series of digit characters. I think that was a point an earlier reply was trying to make: NSNumberFormatter is for numeric values (NSNumber, in particular), not string values that happen to contain digits.

  -- GG

_______________________________________________

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>
  • Prev by Date: Re: base64Binary
  • Next by Date: Question about -awakeAfterusingCoder:
  • Previous by thread: Re: NSNumberFormatter not working for me ?
  • Next by thread: Re: NSNumberFormatter not working for me ?
  • Index(es):
    • Date
    • Thread