def FmtD(x):
    """Return a nicely formatted string for number x."""
    if abs(x - round(x)) < 1e-40:
        return str(int(x))
    if abs(x) < 1e-3:
        return "{:.2e}".format(x)
    return "{:.3f}".format(x)