---
title: "[实用工具类 / 方法] -- 分页中常用到的向上取整获取总页数的简介 【难度 ★★】"
author: "web_in"
date: "2016-08-02T13:43:24Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2016-08-02T13:42:02Z"
id: 2314956
url: "https://web-in.iteye.com/blog/2314956"
---

开发项目中，经常需要用到两数相除后取整，例如分页中，计算显示商品的总页数等，这样的计算是商品总数除以每页显示后的数值再往上取整。

public static void main(String args){
    int rtn_count = 0;
    rtn_count = (int)Math.round( Math.ceil(Float.parseFloat("102") / Float.parseFloat("10")) );
    System.out.println(rtn_count);
}

后台输出的结果是：11

这里模拟的就是如果有102件商品，每页显示10个商品，一共有11页的案例。

其中Math.round是四舍五入函数，Math.ceil是向上取整函数（其参数或者参与运算的参数需为浮点或双精度型数值）