📜  python long numbers as string - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:17.526000             🧑  作者: Mango

代码示例1
import math

def human_format(number):
    units = ['', 'K', 'M', 'G', 'T', 'P']
    k = 1000.0
    magnitude = int(math.floor(math.log(abs(number), k)))
    return f"{number/k**magnitude:.2f}{units[magnitude]}"