I have a picker view that displays output in a textfield. It is for the user to select an amount of time, it has hours, minutes, and seconds for the 3 rows. For this part I only am focusing on the seconds. I want to be able to convert the hours to minutes and display an output as a whole number and a decimal. I was able to convert the hours to minutes, but I am having trouble converting the seconds into a decimal. It should be as simple as dividing the row count by 60. However, I can’t get that to display right. The output to the label is just 0.00 no matter what row i select.. Here is my code.
float sec;
sec = ([timePickerView selectedRowInComponent:2]/60);
Label.text = [NSString stringWithFormat:@"%.2f",sec];
The “/” sign in relation to the number “60” is considered an integer division by the compiler. Change “60” to “60.0” and you shall get the result you are expecting. You should also make sure that the
[timePickerView selectedRowInComponent:2]returns a float by casting it: