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

Here is adapted to you and my own use version of timestr function.

Notice that normal use of time for logging etc becomes easier when can put only timestr() for time values and have fuction to make it human understandable. Use example line+='Processing took '+timestr(t2)+'.\nFinnishing time :' +time.asctime()+'.\n'

import time
def timestr(t):
if t>60: return "%i min %.3f s" % divmod(t,60)
elif t>1: return "%.3f s" % t
else: return "%i ms" % int(t*1000)
def convert(t):
return "%i:%.2f s" % divmod(t,60)
t = float(raw_input('Enter time in s.ss: '))
print convert(t)

Here is adapted to you and my own use version of timestr function.

Notice that normal use of time for logging etc becomes easier when can put only timestr() for time values and have fuction to make it human understandable. Use example line+='Processing took '+timestr(t2)+'.\nFinnishing time :' +time.asctime()+'.\n'

import time
def timestr(t):
if t>60: return "%i min %.3f s" % divmod(t,60)
elif t>1: return "%.3f s" % t
else: return "%i ms" % int(t*1000)
def convert(t):
return "%i:%.2f s" % divmod(t,60)
t = float(raw_input('Enter time in s.ss: '))
print convert(t)

Thank you for your reply and for sharing your code, but it doesn't quite accomplish my original request. I am trying to convert, with appropriate rounding, a float in the format of s.ss to a string that is mm:ss.s, e.g., (using > to denote the conversion)

2.84 > 00:02.8
2.89 > 00:02.9
59.99 > 01:00.0

The need for exactness is due to the fact that the original floats are the racing times of a game.

I am now trying to use divmod and strftime to produce the desired results and will post back if I make any progress...

EDIT:
This seems to work, though lines 5-13 are inelegant:

def convert(time):
t = round(time,1)
minutes , seconds = divmod(t , 60)
if minutes < 10:
minutes = '0%.f' % minutes
else:
minutes = '%.f' % minutes
if seconds < 10:
seconds = '0%.1f' % seconds
else:
seconds = '%.1f' % seconds
return "%s:%s" % (minutes , seconds)
time = float(raw_input('Enter time in s.ss: '))
print convert(time)