NSString *timerend = [[NSString alloc] initWithFormat:@"%.0f:%.0f:%02d", hours, minutes, seconds];
So I have this string and a bunch of floats. For example, say seconds = 6.54. It will display as that. I want it to display as 06.54. Is there anyway to do that? Any help with be greatly appreciated.
Assuming you want the format 'XX:XX:XX.XX' you can use the following code:
NSString *timerend = [[NSString alloc] initWithFormat:@"%02.0f:%02.0f:%05.2f", hours, minutes, seconds];
When formatting float the number before the point (05) determines the minimum total characters in the entire string, not just the bit before the point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With