Re: convert int to NSString (Newbie)
Re: convert int to NSString (Newbie)
- Subject: Re: convert int to NSString (Newbie)
- From: Ricky Sharp <email@hidden>
- Date: Tue, 22 Feb 2005 09:02:09 -0600
On Tuesday, February 22, 2005, at 08:28AM, Sean McBride <email@hidden> wrote:
>On 2005-02-21 16:21, Justin Spahr-Summers said:
>
>>What's there to localize? Besides, the NSNumber descriptionWithLocale:
>>method simply uses %i as a format string with NSString, so there's no
>>difference, except that method allocates an unneeded object.
>
>I am referring to the localisation options in System Preferences >
>International > Formats > Numbers. I tried this code:
>
> int intValue = 10000000;
> NSString* str;
>
> str = [NSString stringWithFormat:@"%d", intValue];
> str = [[NSNumber numberWithInt: intValue] stringValue];
>
>And both methods give the string "10000000". I had incorrectly assumed
>the second method would give a string like "10 000 000", "10,000,000",
>etc. (depending on localisation settings).
>
>Strings displayed to the user should honour their chosen format, but I
>guess I don't know how that's done. :( Anybody?
NSNumberFormatter* theNumberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
NSLog (@"Formatted number is %@", [theNumberFormatter stringForObjectValue:[NSNumber numberWithInt:1000000]]);
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden