Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.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_Division - Fatal编程技术网

将除法结果设为小数点后两位的浮点(Python)

将除法结果设为小数点后两位的浮点(Python),python,division,Python,Division,我知道这是一个noob问题,但是,有没有可能将除法的结果设为小数点后两位的浮点 例如,当50除以2时,结果为25.0。当除以3时,结果为16.668。我可以强制两个结果都是小数点后两位的浮点吗 谢谢,对不起 您可以使用以下内容: x = 16.666666666 rounded_x = format(x, '.2f') #This will be a string 我想你对数字和它们的视觉表现之间的区别感到困惑。。。 >>> round(16.666666666666668,

我知道这是一个noob问题,但是,有没有可能将除法的结果设为小数点后两位的浮点

例如,当50除以2时,结果为25.0。当除以3时,结果为16.668。我可以强制两个结果都是小数点后两位的浮点吗


谢谢,对不起

您可以使用以下内容:

x = 16.666666666
rounded_x = format(x, '.2f') #This will be a string

我想你对数字和它们的视觉表现之间的区别感到困惑。。。
>>> round(16.666666666666668,2)
16.67