robosats/api/nick_generator/utils.py
2022-02-17 11:50:10 -08:00

11 lines
285 B
Python
Executable File

from math import log, floor
def human_format(number):
units = [
"", " Thousand", " Million", " Billion", " Trillion", " Quatrillion"
]
k = 1000.0
magnitude = int(floor(log(number, k)))
return "%.2f%s" % (number / k**magnitude, units[magnitude])