Source code for bittensor.utils.formatting

import math


[docs] def get_human_readable(num, suffix="H"): for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: if abs(num) < 1000.0: return f"{num:3.1f}{unit}{suffix}" num /= 1000.0 return f"{num:.1f}Y{suffix}"
[docs] def millify(n: int): millnames = ["", " K", " M", " B", " T"] n = float(n) millidx = max( 0, min( len(millnames) - 1, int(math.floor(0 if n == 0 else math.log10(abs(n)) / 3)) ), ) return "{:.2f}{}".format(n / 10 ** (3 * millidx), millnames[millidx])