Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ricku425

macrumors newbie
Original poster
Feb 20, 2008
6
0
I am totally new to the whole Obj-C/XCode/IB world, and at the moment, I'm just playing around with some simple i/o stuff. I am wanting to put a double value number into a string. Here's the code I'm trying to use at the moment:

Code:
double value = 123.45678901;
NSString *myString = [NSString stringWithFormat:@"You're double value is %d", value];
[outputTextField setString:myString];

The output, however, shows up as "You're double value is 133744594".

Is it possible to do what I'm trying to do? I've been able to get all the other data types to work (namely int and float) as I would expect them to behave.

Any help for this complete noob would be appreciated...
 

ricku425

macrumors newbie
Original poster
Feb 20, 2008
6
0
Instead of %d, try %lf (that's ell, eff).

%d in C/C++ is for integers. %f is for floats. %lf is for doubles.

Todd

Todd-

Thanks you so much for your reply. That got me half way there (well, technically 82% of the way...). By replacing %d with %lf, the output printed as: "You're double value is 123.456789". However, my double value is actually 123.45678901. That's not too many decimal places for a double value, is it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.