(self, p=0)
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
Return x rounded to the given decimal place.
Return x rounded to the given decimal place .
def round(self, p=0):
        """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

        """
        x = self
        if not x.is_number:
            raise TypeError('%s is not a number' % 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(C.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)  # magnitude needed to bring digit p to units place
        x += 1/(2*mag)  # add the half for rounding
        i10 = 10*mag*x.n((dps if dps is not None else digits_needed) + 1)
        rv = Integer(i10)//10
        q = 1
        if p > 0:
            q = mag
        elif p < 0:
            rv /= mag
        rv = Rational(rv, q)
        if rv.is_Integer:
            # use str or else it won't be a float
            return C.Float(str(rv), digits_needed)
        else:
            return C.Float(rv, allow)
def round ( self , p = 0 ) : x = self if not x . is_number : raise TypeError ( '%s is not a number' % 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 ( C . 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 ) # magnitude needed to bring digit p to units place x += 1 / ( 2 * mag ) # add the half for rounding i10 = 10 * mag * x . n ( ( dps if dps is not None else digits_needed ) + 1 ) rv = Integer ( i10 ) // 10 q = 1 if p > 0 : q = mag elif p < 0 : rv /= mag rv = Rational ( rv , q ) if rv . is_Integer : # use str or else it won't be a float return C . Float ( str ( rv ) , digits_needed ) else : return C . Float ( rv , allow )