(一行代码)Python 科学计数法转普通数值
Python 科学计数法转普通数值
小记
核心主题:通过 ‘%f’ 来将科学计数法转为普通计数
目标:将数值以普通数字形式写入到 ASCII 编码文件中
问题:
1、数值来源于外部,获取到的就是科学计数法
2、懒,只想写一行代码。不想用字符串再做正则匹配,再重新补全数值
解决:
1、获取到的数据如下
[
(-0.00010158695658901706, -3.8247013435466215e-05, -14.133688926696777),
(0.00010158703662455082, 3.824693339993246e-05, -7.853690147399902),
(0.00010158703662455082, 3.824693339993246e-05, -14.133688926696777),
(0.00010158703662455082, 3.824693339993246e-05, 14.133706092834473),
(-0.00010158695658901706, -3.8247013435466215e-05, -7.853690147399902),
(-0.00010158695658901706, -3.8247013435466215e-05, 14.133706092834473),
(0.00010158703662455082, 3.824693339993246e-05, 14.133706092834473),
(-0.00010158695658901706, -3.8247013435466215e-05, -14.133688926696777),
(-0.00010158695658901706, -3.8247013435466215e-05, -7.853690147399902),
(0.00010158703662455082, 3.824693339993246e-05, 14.133706092834473),
(0.00010158703662455082, 3.824693339993246e-05, -7.853690147399902),
(-0.00010158695658901706, -3.8247013435466215e-05, -14.133688926696777)
]
2、我的业务中代码如下
[f.write(f"v {' '.join(map(lambda x: '%f' % x, vertex))}\n") for vertex in
geom.vertexes[start_vertex_ind:end_vertex_ind]]
原理就是:
1)、通过 ‘%f’%coord 来把科学计数法转为普通计数
2)、通过 map 来对每个数值进行转换