Discuss / Python / 第三题

第三题

Topic source
def str2float(s):    dot_index = s.index('.')    str1 = s[:dot_index]    str2 = s[dot_index + 1:]    f1 = reduce(lambda x,y : x*10+y,map(lambda x:int(x),str1))    f2 = reduce(lambda x,y : x*10+y,map(lambda x:int(x),str2))    result = ((f1 * 10**len(str2)) + f2) / (10**len(str2))     print(result)str2float('123.456')

  • 1

Reply