def formatted(f):
    return format(f, '.2f').rstrip('0').rstrip('.')
formatted(0.0)
formatted(4.797)
formatted(4.001)
formatted(13.577)
formatted(1e-21)
formatted(10000000000)
Most Pythonic way to print *at most* some number of decimal places