[Python] Can't eliminate floating point errors with Decimal

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Decimal everywhere to try and get rid of floating point errors, but it's persisting.

    Here's my test code

    from decimal import Decimal
    Demands = [9,12,8,11]


    fM = Decimal(10)

    alpha = Decimal(.01)

    fM = Decimal((1 - Decimal(alpha)) * fM + Decimal(alpha) * Demands[(1) % 4])

    print(fM)


    But the output is still

    10.02000000000000000041633363

    Continue reading...

Compartilhe esta Página