ceil()函数,用于返回数字的上入整数。

本人在用python做web网站,后端做到翻页功能的时候,会用到math.ceil()函数来实现。

比如:

前端规定每页的数据为20条:size=20

后端从数据库取到符合条件的总数据为:count=50

这样得到的页数max_page应该是3页(count/size=2.5,  取上入整数即整数3),需要用到math中的ceil来实现。

输入代码:

# python的内建函数ceil()
import math

print(math.ceil(-14.5))
print(math.ceil(50))
print(math.ceil(60.2))
print(math.ceil(math.pi))

输出:

Python 内建函数——ceil()函数

 

 

 

转载于:https://my.oschina.net/xxWang/blog/804366

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2022-01-19
  • 2021-10-17
猜你喜欢
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-12-10
  • 2021-08-10
  • 2022-12-23
相关资源
相似解决方案