Discuss / Python / int转float

int转float

Topic source

玹帝

#1 Created at ... [Delete] [Delete and Lock User]

digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} def char2num(s): return digits[s] def str2float(s): return reduce(lambda x,y:x10+y,map(char2num,s.replace('.','')))/(10*(len(s)-s.find('.')-1))


  • 1

Reply