当前位置:主页 > 软件编程 > Python代码 >
时间:2021-06-14 09:46:58 | 栏目:Python代码 | 点击:次
向上取整的方法:
方法1:
items = 102 boxsize = 10 num_boxes = (items + boxsize - 1) // boxsize
方法2:
>>> -(-102 // 10) 11
方法3(浮点数向上取整):
from math import ceil print(ceil(10.3)) 11
或
import math math.ceil( x )