@staticmethod
    def format_int(num, units='kMGTPEZY'):
        # width: 1~6
        # examples:
        # 0: 0
        # 1: 1
        # 10: 10
        # 100: 100
        # 1000: 1.0K
        # 10000: 10.0K
        # 100000: 100.0K
        # 1000000: 1.0M
        # -10: -11
        unit = None
        unit_iter = iter(units)
        while abs(round(num, 1)) >= 1e3:
            num /= 1e3
            try:
                unit = next(unit_iter)
            except StopIteration:
                # overflow or underflow.
                return 'o/f' if num > 0 else 'u/f'
        if unit is None:
            return '{:.0f}'.format(num)
        else:
            return '{:.1f}{}'.format(num, unit)
dataset/ETHPy150Open what-studio/profiling/profiling/viewer.py/Formatter.format_int/original