(self, ndigits=None)
round(self, ndigits)

        Rounds half toward even.
round(self, ndigits)
round ( self ndigits )
def __round__(self, ndigits=None):
        """round(self, ndigits)

        Rounds half toward even.
        """
        if ndigits is None:
            floor, remainder = divmod(self.numerator, self.denominator)
            if remainder * 2 < self.denominator:
                return floor
            elif remainder * 2 > self.denominator:
                return floor + 1
            # Deal with the half case:
            elif floor % 2 == 0:
                return floor
            else:
                return floor + 1
        shift = 10**abs(ndigits)
        # See _operator_fallbacks.forward to check that the results of
        # these operations will always be Fraction and therefore have
        # round().
        if ndigits > 0:
            return Fraction(round(self * shift), shift)
        else:
            return Fraction(round(self / shift) * shift)
def __round__ ( self , ndigits = None ) : if ndigits is None : floor , remainder = divmod ( self . numerator , self . denominator ) if remainder * 2 < self . denominator : return floor elif remainder * 2 > self . denominator : return floor + 1 # Deal with the half case: elif floor % 2 == 0 : return floor else : return floor + 1 shift = 10 ** abs ( ndigits ) # See _operator_fallbacks.forward to check that the results of # these operations will always be Fraction and therefore have # round(). if ndigits > 0 : return Fraction ( round ( self * shift ) , shift ) else : return Fraction ( round ( self / shift ) * shift )