robosats/api/nick_generator/utils.py

9 lines
269 B
Python
Raw Normal View History

from math import log, floor
2022-02-17 19:50:10 +00:00
def human_format(number):
2022-10-20 09:56: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])