[英]Python : round a decimal number
我在我的軟件中得到一個數字,如果這個數字是十進制數字,我想應用一個過程。
我想將我的數字四舍五入到大整數。
例如 :
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>)
例子 :
>>> import math
>>> math.ceil(1.3)
2
>>> math.ceil(1.7)
2
>>> math.ceil(2.0)
2
>>> math.ceil(2.1)
3
你好,你想要的方法是圓的
a = 1
b = 2
c = round(b/a)
print(c)
>>>> 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.