robosats/api/nick_generator/utils.py

11 lines
285 B
Python
Raw Normal View History

from math import log, floor
2022-02-17 19:50:10 +00:00
def human_format(number):
2022-02-17 19:50:10 +00:00
units = [
"", " Thousand", " Million", " Billion", " Trillion", " Quatrillion"
]
k = 1000.0
magnitude = int(floor(log(number, k)))
2022-02-17 19:50:10 +00:00
return "%.2f%s" % (number / k**magnitude, units[magnitude])