views:

926

answers:

2

I am new to Objective C and the iPhone SDK, and am trying to figure out the following as a simple example of displaying a numeric result in a label area:

label.text = [NSString stringWithFormat: @"%d", 55];

This code above displays the number "55" in the label area. However, the following code results in the display of "0" (with calculationResult declared as a double variable type in the header file):

calculationResult = 55;
label.text = [NSString stringWithFormat: @"%d", calculationResult];

Any help is much appreciated.

+3  A: 

You should use %f for a float or double. If you don't want to print any decimal places, you should use %.0f.

Benno
A: 

If you want to display a double, use the %f notation, not %d - %d is for decimal numbers, while %f is for floating point types (including doubles).

Tim