Python向上取整

一、场景:

  有时候我们分页展示数据的时候,需要计算页数。一般都是向上取整,例如counts=205 pageCouts=20 ,pages= 11 页。

方法:

  • 通用除法:取临界值,计算下A+B-1的范围就OK
pages = int((A+B-1)/B)
pages = int((205 + 10 -1)/10)
  • Python match.ceil函数:
import math
pages = math.ceil(float(205)/20)
posted @ 2022-09-02 13:41  大切切  阅读(220)  评论(0编辑  收藏  举报