Discuss / Python / 字符串数值转为浮点数

字符串数值转为浮点数

Topic source

Runner

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

#将字符串123.456转为浮点数123.456

s='123.456'

d = {str(x):x for x in range(10)}

print(reduce(lambda x,y:x*10+y,map(lambda i:d.get(i),s.split('.')[0]+s.split('.')[1]))/10**len(s.split('.')[1]))


  • 1

Reply