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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -