import math


def _fraction2str(num, decimals=2):
    """
    Helper method to pretty print percentages.
    Args:
        num: A number in the range [0,1].
    """
    if isinstance(num, str):
        return num
    mult = math.pow(10, decimals)
    if num < 0.5/mult:
        return "0"
    ret = str(int(num*mult+.5)/float(mult))
    if len(ret) < decimals+2:
        ret += "0"
    if ret[0] == "0":
        return ret[1:]
    return ret