iphone - Format a float to display in a string with two digits? -
nsstring *timerend = [[nsstring alloc] initwithformat:@"%.0f:%.0f:%02d", hours, minutes, seconds];
so have string , bunch of floats. example, seconds = 6.54. display that. want display 06.54. there anyway that? appreciated.
assuming want format 'xx:xx:xx.xx' can use following code:
nsstring *timerend = [[nsstring alloc] initwithformat:@"%02.0f:%02.0f:%05.2f", hours, minutes, seconds];
when formatting float number before point (05) determines minimum total characters in entire string, not bit before point.
Comments
Post a Comment