python中如何限制小数点后的位数
我使用的代码是:python中如何限制小数点后的位数,python,Python,我使用的代码是:newAgent=[random.gauss(0,1),random.gauss(0,1)] 我想限制小数点后的位数。现在大约是20位。答案很简单。只需使用round,然后用,#空格数指定位置。在本例中,我对5个十进制空间进行了修改 import random newAgent = [random.gauss(0, 1), random.gauss(0, 1)] print(round(newAgent[0], 5), round(newAgent[1], 5))
newAgent=[random.gauss(0,1),random.gauss(0,1)]
我想限制小数点后的位数。现在大约是20位。答案很简单。只需使用
round
,然后用,#空格数
指定位置。在本例中,我对5个十进制空间进行了修改
import random
newAgent = [random.gauss(0, 1), random.gauss(0, 1)]
print(round(newAgent[0], 5), round(newAgent[1], 5))