Given s.ss or seconds accurate to the hundredth place, what is the most effective way to convert it to the string mm:ss.s?
Here is my current attempt:
import time
def convert(t):
print time.strftime("%M:%S",time.gmtime(round(t,1)))+str((".%01d" % (((round(t,1))-int(round(t,1)))*10)))
t = float(raw_input('Enter time in s.ss: '))
convert(t)
However, the results don't seem quite right:
>>>
Enter time in s.ss: 2.84
00:02.7
It seems like round(t,1) doesn't do its job right:
>>> round(2.84,1)
2.7999999999999998
Any suggestions?
Thank you for your help,
cyon
Other problems:
- strftime doesn't round any of the decimals