开发者

Calculation to get page count based on # of items

开发者 https://www.devze.com 2023-01-09 22:36 出处:网络
If I have 177 items, and each page has 10 items that means I\'ll have 18 pages. I\'m new to python and having used any of the math related functions.

If I have 177 items, and each page has 10 items that means I'll have 18 pages.

I'm new to python and having used any of the math related functions.

How can I calculate 177/10 and then get round up so I get 18 and no开发者_Python百科t 17.7


import math
math.ceil(float(177)/10)


You can do it with integer arithmetic:

items_per_page = 10
number_of_pages = (x + items_per_page - 1) // items_per_page
0

精彩评论

暂无评论...
验证码 换一张
取 消