def nice_frequency(frequency):
    """return a string of the frequency with SI unit and a reasonable number
       of digits"""
    if frequency < 1000.0:
        return '%dHz' % frequency
    elif frequency < 10000.0:
        return '%.3fkHz' % (frequency / 1000.0)
    elif frequency < 100000.0:
        return '%.2fkHz' % (frequency / 1000.0)
    elif frequency < 1000000.0:
        return '%.1fkHz' % (frequency / 1000.0)
    elif frequency < 10000000.0:
        return '%.3fMHz' % (frequency / 1000000.0)
    elif frequency < 1000000000.0:
        return '%.2fMHz' % (frequency / 1000000.0)
    return '%.2fGHz' % (frequency / 1000000000.0)
