简体   繁体   English

从科学记数法中提取指数

[英]Extracting the exponent from scientific notation

I have a bunch of numbers in scientific notation and I would like to find their exponent.我有一堆科学记数法的数字,我想找到它们的指数。 For example:例如:

>>> find_exp(3.7e-13)
13

>>> find_exp(-7.2e-11)
11

Hence I only need their exponent ignoring everything else including the sign.因此,我只需要他们的指数而忽略包括符号在内的所有其他内容。

I have looked for such a way in python but similar questions are only for formatting purposes.我在 python 中寻找过这种方式,但类似的问题仅用于格式化目的。

Common logarithm is what you need here, you can use log10 + floor :常用对数是您在这里需要的,您可以使用log10 + floor

from math import log10, floor

def find_exp(number) -> int:
    base10 = log10(abs(number))
    return abs(floor(base10))

find_exp(3.7e-13)
# 13

find_exp(-7.2e-11)
# 11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM