Rounding Error on Anvil

What I’m trying to do:
Why is it that when I run the following code:

print(round(0.81,2))

It always returns “0.8100000000000001”, but the output should be “0.81” (which I get on other compilers and other numbers) but for the number 0.81 specifically, I keep receiving this long number with lots of trailing zeros and a 1.

image

The rounding works correctly.

I think you want to format, rather than round, the number to a string that shows only two digits.

This question has already been answered here: Stange rounding of numbers in Confirmation - #2 by stefano.menci

1 Like