[Python] python incorrect rounding with floating point numbers

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    >>> a = 0.3135
    >>> print("%.3f" % a)
    0.314
    >>> a = 0.3125
    >>> print("%.3f" % a)
    0.312
    >>>


    I am expecting 0.313 instead of 0.312 Any thought on why is this, and is there alternative way I can use to get 0.313?

    Thanks

    Continue reading...

Compartilhe esta Página