import math
def maximum_number_of_digits(num: float):
"""
:param num:
:return: 个位是第0位,小数点后第一位是-1位,以此类推~
"""
if num == 0:
return None
return math.floor(math.log10(abs(num)))
assert maximum_number_of_digits(5201314) == 6
assert maximum_number_of_digits(-5201314) == 6
assert maximum_number_of_digits(520.1314) == 2
assert maximum_number_of_digits(1/5) == -1
assert maximum_number_of_digits(math.pi) == 0
assert maximum_number_of_digits(0.000000000000000001) == -18
assert maximum_number_of_digits(0) is None
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)