Re: Need help to make these methods prettier
Re: Need help to make these methods prettier
- Subject: Re: Need help to make these methods prettier
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 01 Nov 2008 20:51:29 -0700
On Nov 1, 2008, at 10:31 AM, Andre Masse wrote:
- formatting a number from 123456789 to 123 456 789
and to get the number back:
- (IBAction)rollback:(id)sender
{
NSString *strWithSpaces = [aResult stringValue];
...
}
I didn't see this part of your original question. NSNumberFormatter
can do that, too.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSArray *a = [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedLongLong: 12],
[NSNumber numberWithUnsignedLongLong: 1234],
[NSNumber numberWithUnsignedLongLong: 12345678],
[NSNumber numberWithUnsignedLongLong: 1234567890123],
nil];
NSNumberFormatter *nf = [NSNumberFormatter new];
[nf setNumberStyle: NSNumberFormatterDecimalStyle];
[nf setGroupingSeparator: @" "];
for(NSNumber *n in a) {
NSString *aString = [nf stringFromNumber:n];
NSLog(@"%@ => %@ => %@", n, aString, [nf numberFromString:
aString]);
}
return 0;
}
Spews:
2008-11-01 20:51:03.761 format[2062:10b] 12 => 12 => 12
2008-11-01 20:51:03.768 format[2062:10b] 1234 => 1 234 => 1234
2008-11-01 20:51:03.771 format[2062:10b] 12345678 => 12 345 678 =>
12345678
2008-11-01 20:51:03.772 format[2062:10b] 1234567890123 => 1 234 567
890 123 => 1234567890123
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