Recently, during the development of the project , Use Python Write a little tool for testing , one day , The test raises an incredible question ：
The result of the accumulation of decimals , It's always puzzling
So , I open it, too Python Of IDLE To test ：
forehead , It looks like this .
Through my simple thinking , I think it should be the problem that the accuracy of floating-point numbers on the bottom of the computer is not accurate , Through my Internet search related information , It also confirms my conjecture .
This blog is very good ：
Python： The problems and limitations of floating point operations
The reason is found , So how to solve the problem ？
In fact, it can be , For example, keep your results 2 Bit accuracy , So finally, add one round Method to keep the rounded digits ：
I hope this blog can bring you some help ：）