Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中如何限制小数点后的位数_Python - Fatal编程技术网

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))