Floating point numbers are only approximations; 2.85 cannot be represented exactly:
>>> format(2.85, '.53f')
'2.85000000000000008881784197001252323389053344726562500'
It is slightly over 2.85.
0.5 and 0.75 can be represented exactly with binary fractions (1/2 and 1/2 + 1/4, respectively).
The round()
function documents this explicitly:
Note: The behavior of
round()
for floats can be surprising: for example,round(2.675, 2)
gives2.67
instead of the expected2.68
. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information.