This is a complete or consistent problem. Representing floating point is hard. Canadian national treasure Julia Evans describes this quite well: Why does 0.1 + 0.2 = 0.30000000000000004?I am solidly of the opinion there should be no rounding.
Try this in a CPython REPL, and then in a MicroPython REPL:
Code:
a=0.1+0.2b=0.3a==b
CPython has the handy math.as_integer_ratio() and math.nextafter() functions to debug what's inside a floating point number. MicroPython doesn't have these. But we do know that MicroPython uses the standard log₂x = log(x)/log(2.0) identity with limited precision floating point values. And that's one of the OP's problems. That, and using int() when one really means round().
Statistics: Posted by scruss — Mon Apr 28, 2025 4:53 pm