[Python] Why 3.0/100.0 == 0.3/10.0 gives True? [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I learned that 0.1 + 0.2 != 0.3 due to the 0.1 and 0.2 are both not accurately 0.1 and 0.2.

    However, why the following Python code prints out "True"?

    float1 = 1.0/100.0
    float2 = 0.1/10.0
    print( float1 == float2 )


    Same applies to C:

    double slope1 = 1.0 / 100.0;
    double slope2 = 0.1 / 10.0;

    int main(int argc, const char * argv[]) {
    printf( "%d", slope1 == slope2 );
    }


    What did I miss or misunderstand? kindly teach.

    Continue reading...

Compartilhe esta Página