I have a simple function that returns a floating point number as follows.
float offset (int secs){
return secs/3600;
}
Given secs = 19800, if I use it in the following, I end up getting 5 instead of 5.5.
num01.text=[NSString stringWithFormat:@"%.1f",offset(t01)]; // t01 is 19800
What am I doing wrong? What can I do to set the string value of num01 (label) to 5.5 ?
Thank you for your help.
The return value is an int before it’s parsed as a float.
Simply cast one of the operands as a float or use 3600.0: