Displaying numeric value in iPhone shortcut area using stringWithFormat

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

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

      

This code shows the number "55" in the label area. However, the following code results in displaying "0" (with the computationResult declared as a double variable type in the header file):

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

      

Any help is greatly appreciated.

+2


source to share


2 answers


You must use %f

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

.



+19


source


If you want to display double, use the notation %f

, not %d

- %d

for d , but %f

for f point types (including paired ones).



0


source







All Articles