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

Python:将十进制数四舍五入

Python:将十进制数四舍五入,python,ceil,Python,Ceil,我在我的软件中得到一个数字,如果这个数字是十进制数,我想应用一个过程 我想把我的数字四舍五入到整数的上限 例如: Get number --> expected 1.3 --> 2 1.7 --> 2 2.0 --> 2 2.1 --> 3 有可能创造出这样的东西吗? 我正在寻找拆分函数: x = 3.4 x1 = int(round(x)) returns : 3 and not 4 提前向您表示感谢,如果我没有找到问题的解决方案,我正在寻找。使用以下方法:

我在我的软件中得到一个数字,如果这个数字是十进制数,我想应用一个过程

我想把我的数字四舍五入到整数的上限

例如:

Get number --> expected
1.3 --> 2
1.7 --> 2
2.0 --> 2
2.1 --> 3
有可能创造出这样的东西吗? 我正在寻找拆分函数:

x = 3.4
x1 = int(round(x))
returns : 3 and not 4
提前向您表示感谢,如果我没有找到问题的解决方案,我正在寻找。

使用以下方法:

import math
math.ceil(<decimal>)

你好,你想要的方法是圆的

a = 1
b = 2

c = round(b/a)
print(c)
>>>> 0

如果类型(x)=‘float’:可能重复的
math.ceil(decimal.decimal('3.5'))
,或者类似的内容,这取决于您输入的确切内容和您想要的精度。
round
不是您要寻找的术语。它是
ceil
round()
将值舍入到最接近的整数,其中as
ceil()
始终将其舍入到更高的整数。正如
round(1.3)
1
round(1.7)
2
但是
math.ceil(1.3)
2
math.ceil(1.7)
也是
2
a = 1
b = 2

c = round(b/a)
print(c)
>>>> 0