import math


def percent(n, precision=0):
    """
    Converts `n` to an appropriately-precise percentage.
    """
    
    # 'or 1' prevents a domain error if n == 0 (i.e., 0%)
    places = precision - math.floor(math.log10(abs(n) or 1))
    return '{0:.{1}%}'.format(n, places)