Python float omitted

1.
There are some strange phenomena in floating-point multiplication in Python, such as the following

0.58*100 = 57.999999
int(57.999999)             #58 

Such results are obviously not ideal, but for

0.56*100 = 56.00000000000001
int(0.56*100) = 56

And this seems to be normal again, so how to solve the 0.58 one? int(round(0.58*100)) is enough, do not use ceil or floor instead, otherwise it will not meet other situations.

int(round(0.58*100))

See the strange floating-point phenomenon for the reason of this situation.
Usually, such an error still occurs in the code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325741116&siteId=291194637