Arduino IDE returns the result different from a mathematical calculation

Hello!

I'm breaking my head a little because I'm performing a mathematical formula in which the compiler returns a completely different result than the calculator.

    Serial.print("TEST: ");
    Serial.println((12-(12/31)*31));

15:27:00.261 -> TEST: 12

However, on the calculator the result of this calculation is 0.
Would anyone know why the result in the Arduino IDE is 12?

Thanks!

In integer math, 12/31 = 0.

I've forgotten the "little rules" but 12.0/31.0 will probably fix it.

It's true, I forgot that detail. I kept thinking about a thousand possibilities instead of the obvious lol

thank you very much

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.