如何舍入整数除法的结果? [英] How to round up the result of integer division?
本文介绍了如何舍入整数除法的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我特别考虑在使用 C# 或 Java 等语言时如何显示分页控件.
I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java.
如果我想在每页 y 块中显示 x 个项目,需要多少页?
If I have x items which I want to display in chunks of y per page, how many pages will be needed?
推荐答案
找到了一个优雅的解决方案:
Found an elegant solution:
int pageCount = (records + recordsPerPage - 1) / recordsPerPage;
来源:数字转换,Roland Backhouse,2001 年一个>
这篇关于如何舍入整数除法的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文