'Return x rounded to the given decimal place.
If a complex number would results, apply round to the real
and imaginary components of the number.
Examples
>>> from sympy import pi, E, I, S, Add, Mul, Number
>>> S(10.5).round()
11.
>>> pi.round()
3.
>>> pi.round(2)
3.14
>>> (2*pi + E*I).round()
6. + 3.*I
The round method has a chopping effect:
>>> (2*pi + I/10).round()
6.
>>> (pi/10 + 2*I).round()
2.*I
>>> (pi/10 + E*I).round(2)
0.31 + 2.72*I
Notes
Do not confuse the Python builtin function, round, with the
SymPy method of the same name. The former always returns a float
(or raises an error if applied to a complex value) while the
latter returns either a Number or a complex number:
>>> isinstance(round(S(123), -2), Number)
False
>>> isinstance(S(123).round(-2), Number)
True
>>> isinstance((3*I).round(), Mul)
True
>>> isinstance((1 + 3*I).round(), Add)
True'

def round(self, p=0):

    from sympy import Float
    x = self
    if (not x.is_number):
        raise TypeError("can't    round    symbolic    expression")
    if (not x.is_Atom):
        xn = x.n(2)
        if (not pure_complex(xn, or_real=True)):
            raise TypeError(('Expected    a    number    but    got    %s:' % getattr(getattr(x, 'func', x), '__name__', type(x))))
    elif (x in (S.NaN, S.Infinity, S.NegativeInfinity, S.ComplexInfinity)):
        return x
    if (not x.is_real):
        (i, r) = x.as_real_imag()
        return (i.round(p) + (S.ImaginaryUnit * r.round(p)))
    if (not x):
        return x
    p = int(p)
    precs = [f._prec for f in x.atoms(Float)]
    dps = (prec_to_dps(max(precs)) if precs else None)
    mag_first_dig = _mag(x)
    allow = digits_needed = (mag_first_dig + p)
    if ((dps is not None) and (allow > dps)):
        allow = dps
    mag = Pow(10, p)
    xwas = x
    x += (1 / (2 * mag))
    i10 = ((10 * mag) * x.n(((dps if (dps is not None) else digits_needed) + 1)))
    if i10.is_negative:
        x = (xwas - (1 / (2 * mag)))
        i10 = ((10 * mag) * x.n(((dps if (dps is not None) else digits_needed) + 1)))
        rv = (- (Integer((- i10)) // 10))
    else:
        rv = (Integer(i10) // 10)
    q = 1
    if (p > 0):
        q = mag
    elif (p < 0):
        rv /= mag
    rv = Rational(rv, q)
    if rv.is_Integer:
        return Float(str(rv), digits_needed)
    else:
        if ((not allow) and (rv > self)):
            allow += 1
        return Float(rv, allow)
