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 (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 [EMAIL PROTECTED]

Reply via email to