Re: Need help to make this method prettier
Re: Need help to make this method prettier
- Subject: Re: Need help to make this method prettier
- From: Graff <email@hidden>
- Date: Sat, 1 Nov 2008 15:30:06 -0400
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?
Just a quick example:
// get a number by any means possible
unsigned int theNumber = 1123456789;
// truncate numbers that are too large
theNumber = theNumber % 1000000000;
NSMutableString *numberString;
// turn the number into a string padded with zeros to 9 places
numberString = [NSMutableString stringWithFormat:@" d", theNumber];
// add a space character to position 6
[numberString insertString:@" " atIndex:6];
// add a space character to position 3
[numberString insertString:@" " atIndex:3];
// numberString is now formatted in the format "xxx xxx xxx"
_______________________________________________
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