How to deal with ending 5 in decimal when rounding

I used python to round floating point numbers, and I am confused about how round numbers of computers are. For instance:

round(1.55, 1) = 1.6 # this is what I would expect; however
round(1.65, 1) = 1.6 #this is what confuses me. Is it supposed to be 1.7?

Another example:

round(1.85, 1) = 1.9
round(1.95, 1) = 1.9

I suppose this may have something to do with the conversion between binary and decimal. My question is, how can I find out if end 5 is omitted or not? Thank you so much for your help!

+4
source share
1 answer

The documentation describes why this happens:

round() : , (2,675, 2) 2,67 2,68. : , . . : .

, , .

:

round() , , . 2.675 2,67 2,68, , ( ) 2.68. , 2.675 , ,

2,67499999999999982236431605997495353221893310546875

2,67, 2,68, .

+3

All Articles