@staticmethod
    def format_percent(ratio, denom=1, unit=False):
        # width: 4~5 (with unit)
        # examples:
        # 0.01: 1.00%
        # 0.1: 10.0%
        # 1: 100%
        try:
            ratio /= float(denom)
        except ZeroDivisionError:
            ratio = 0
        if round(ratio, 2) >= 1:
            precision = 0
        elif round(ratio, 2) >= 0.1:
            precision = 1
        else:
            precision = 2
        string = ('{:.' + str(precision) + 'f}').format(ratio * 100)
        if unit:
            return string + '%'
        else:
            return string
dataset/ETHPy150Open what-studio/profiling/profiling/viewer.py/Formatter.format_percent/original