Python round method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python round method

When I type round(767.87836565, 3) it gives me 767.878000000002. Why and how to neutralize this problem?

1st May 2017, 9:01 PM
Kuba Nawieśniak
Kuba Nawieśniak - avatar
1 Answer
+ 4
Since floating point numbers are based on binary arithmetic (the base 2 method of counting), the result you've obtained is correct from the machine point of view, but is not familiar to what people have in mind commonly. I suggest to consider decimal as a valid alternative. Have a look here:
1st May 2017, 10:12 PM
Davide Corbelletto
Davide Corbelletto - avatar