• 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: Need help to make this method prettier
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help to make this method prettier


  • Subject: Re: Need help to make this method prettier
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 01 Nov 2008 13:09:07 -0700

On Nov 1, 2008, at 1:56 PM, Andre Masse wrote:
I'm implementing a custom NSFormatter. I want a number with 9 digits
displayed as "123 456 789". So before implementing the formatter I
made a test project to check the conversion. The version I did get the
job done but its not pretty :-) Any more good looking solutions?

Use the APIs whenever possible.

int main (int argc, const char * argv[]) {
NSArray *a = [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedLongLong: 12],
[NSNumber numberWithUnsignedLongLong: 1234],
[NSNumber numberWithUnsignedLongLong: 12345678],
[NSNumber numberWithUnsignedLongLong: 123456789012345678],
nil];


    NSNumberFormatter *nf = [NSNumberFormatter new];
    [nf setNumberStyle: NSNumberFormatterDecimalStyle];
    [nf setGroupingSeparator: @" "];

    for(NSNumber *n in a)
        NSLog(@"%@ => %@", n, [nf stringFromNumber:n]);

    return 0;
}

Spews:

2008-11-01 13:05:46.881 format[1350:10b] 12 => 12
2008-11-01 13:05:46.882 format[1350:10b] 1234 => 1 234
2008-11-01 13:05:46.883 format[1350:10b] 12345678 => 12 345 678
2008-11-01 13:05:46.883 format[1350:10b] 123456789012345678 => 123 456 789 012 345 678


b.bum

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Need help to make this method prettier
      • From: Andre Masse <email@hidden>
References: 
 >Re: Need help to make this method prettier (From: Graff <email@hidden>)

  • Prev by Date: Re: Need help to make this method prettier
  • Next by Date: Re: [Q] Buttons with Menus
  • Previous by thread: Re: Need help to make this method prettier
  • Next by thread: Re: Need help to make this method prettier
  • Index(es):
    • Date
    • Thread