我正在使用Python进行一些计算。在一个步骤中,将出现如下数组

[1.23e-21, 2.32e-14, 8.87e-12, .....]


我只想获取e..之前的部分,即我想要获取数组

[1.23, 2.32, 8.87,.....]


有什么方法可以做到这一点?

最佳答案

可能的许多解决方案之一:

from math import floor, log10

x = [1.23e-21, 2.32e-14, 8.87e-12, 1.51, 1.214e10]

res = [t/10**floor(log10(abs(t))) if t!= 0 else 0 for t in x]

09-20 22:38