def output_as_percentage(num, fractional_digits=1):
    """Output a percentage neatly.

    fractional_digits = number of digits to output as fractions of a percent.
    If None is supplied, there is no reduction in precision."""
    if fractional_digits is not None:
        format_str = '%%.%.df' % fractional_digits
    else:
        format_str = '%f'
    return '%s%%' % (format_str % num)
