Re: Formating a number in a string
Re: Formating a number in a string
- Subject: Re: Formating a number in a string
- From: Joe Lertola <email@hidden>
- Date: Sun, 14 Mar 2004 10:22:33 -0500
Oh, thanks so much.
I don't understand what you mean by "at a terminal (or use Xcode)".
When I type "printf" into the Help window, for example, I don't get any
info for the printf function. Is there a way to access help for basic C
statements?
Again, sorry for this total beginner question.
Thanks,
-Joe Lertola
On Mar 14, 2004, at 9:56 AM, Chris Ridd wrote:
On 14/3/04 2:23 pm, Joe Lertola <email@hidden> wrote:
Hi all,
I am new to cocoa and C programming in general, so I hope you will
excuse me if I ask an obvious question. I have been puttering around
the help system for over an hour without finding the answer to this.
I want to add a floating point number to string as in this example
below:
float sec;
NSString *degreeString;
sec = 123.44;
degreeString = [NSString stringWithFormat: @"my number is %f",
sec];
When I run this I get a string like this:
"my number is 123.440002"
How can I limit the number that is inserted into the string to two
decimal places?
Replace the "%f" with "%.2f". This notation is from the standard C
printf
family of functions - if you type 'man printf' at a terminal (or use
Xcode)
then you should see the other things you can do.
Cheers,
Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.