Python how to retain control float several decimal places

There are several decimal places to retain a good use of the function round, any float can leave to the specified number of digits.
E.g

a=3.1415926535
print(round(a,3))
#输出为3.142

Obviously the result is automatically rounded.
If we direct round (a), it returns an integer

a=3.1415926535
print(round(a))
#输出为3
Published 35 original articles · won praise 74 · views 6778

Guess you like

Origin blog.csdn.net/weixin_45939019/article/details/104198751