[Python] How to avoid incorrect rounding with numpy.round?

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with floating point numbers. If I do:

    import numpy as np
    np.round(100.045, 2)


    I get:

    Out[15]: 100.04


    Obviously, this should be 100.05. I know about the existence of IEEE 754 and that the way that floating point numbers are stored is the cause of this rounding error.

    My question is: how can I avoid this error?

    Continue reading...

Compartilhe esta Página