def forg(x, prec=3):
    """
    Yanked from the code for Statsmodels\\iolib\\summary.py
    and adjusted
    """
    if prec == 3:
        if abs(x) >= 10000.0 or abs(x) < 0.0001:
            return '%9.3g' % x
        else:
            return '%9.3f' % x
    elif prec == 4:
        if abs(x) >= 10000.0 or abs(x) < 0.0001:
            return '%10.4g' % x
        else:
            return '%10.4f' % x
    else:
        raise NotImplementedError
