Python - string format - integral part of decimals -


i need convert numeric time value lrc time format. here wrote

def lrc_time(t):     seconds = int(t)     millis = t - seconds     return '[%02d:%02.2f]' % (seconds / 60, seconds % 60 + millis) 

the code runs as

>>> print lrc_time(20.5) [00:20.50] >>> print lrc_time(65.0) # suppose "[01:05.00]", [01:5.00] 

the problem is, unlike %02d, %02.2f won't padding 0 before integral part when number less 10. in fact seems same %.2f.

so what's correct way that?

i got work with:

"%05.02f" % (4.5623,) 

so that's saying prefix zero, number string have width of 5 characters (in case 2 whole number digits, period, , 2 decimal digits), , 2 decimal point precision.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -