Reading today " Python introduction - The road to master ( Deep wisdom , 2018)" When you see round() Examples of functions , The function of this function is called rounding , I always thought round() It's round , But sometimes it's rounding , Sometimes it's rounding , If there is such a misunderstanding in numerical calculation , It is possible to accumulate small differences into large differences and get wrong results , for example :
round(0.4) # 4 House
0round(0.5) # 5 House
0round(0.6) # 6 Enter into
1
As can be seen from this example round() It's not really rounding , But the following example is a face rounding statement :
round(0.47) # 4 House
0round(0.57) # 5 Enter into
1round(0.67) # 6 Enter into
1
This example shows that sometimes it is rounded , Sometimes it's rounding , What is the reason ?
In fact, this is because the computer is a binary numerical system , It can store integers accurately , But floating point numbers cannot be stored accurately , It stores only approximate values , It is the error of this approximation that makes round