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.
You should use %f
for a float or double. If you don't want to print any decimal places, you should use %.0f
.