# -*- ciding: utf-8 -*- from functools import reduce def str2float(s): s = s.split(".", 1) def fn(x, y): return x * 10 + y return reduce(fn, map(int, s[0])) + reduce(fn, map(int, s[1]))/(10 ** len(s[1])) print('str2float(\'123.456\') =', str2float('123.456')) if abs(str2float('123.456') - 123.456) < 0.00001: print('测试成功') else: print('测试失败')
Sign in to make a reply
SherryMaoMAO