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
Can';t正确使用python的round函数_Python_Python 3.x_Rounding - Fatal编程技术网

Can';t正确使用python的round函数

Can';t正确使用python的round函数,python,python-3.x,rounding,Python,Python 3.x,Rounding,我正在获得输出15.36,但我只想要15。我正在使用round函数,例如round(15.36,2),但仍然得到相同的结果。使用 round(数字,ndigit) 因此,对于您的示例,使用round(15.36,0)文档非常好地解释了函数的参数: round(数字[,ndigit]) 返回数值在小数点后四舍五入到ndigits精度。如果ndigits被省略或为None,它将返回与其输入最接近的整数 因此,如果要舍入到最接近的整数,只需在不使用第二个参数的情况下使用它: >>>

我正在获得输出
15.36
,但我只想要
15
。我正在使用round函数,例如
round(15.36,2)
,但仍然得到相同的结果。

使用

round(数字,ndigit)


因此,对于您的示例,使用
round(15.36,0)

文档非常好地解释了函数的参数:

round(数字[,ndigit])

返回数值在小数点后四舍五入到ndigits精度。如果ndigits被省略或为None,它将返回与其输入最接近的整数

因此,如果要舍入到最接近的整数,只需在不使用第二个参数的情况下使用它:

>>> round(15.36)
15

第二个参数是小数位数(即
右侧的位数)——请尝试
四舍五入(15.36,0)