[Python] Why does the floordiv (//) operator with python decimals round toward 0 instead of...

Discussão em 'Python' iniciado por Stack, Julho 19, 2025.

  1. Stack

    Stack Membro Participativo

    >>> import decimal
    >>> decimal.Decimal(-7) // 4
    Decimal('-1') # Result rounded towards 0.
    >>> -7 // 4
    -2 # Result rounded towards negative infinity.


    Why does the floordiv operator with a python decimal round towards 0 instead of towards negative infinity, as the floordiv operator does with all other types?

    Continue reading...

Compartilhe esta Página