I use it occasionally, so make a note.
The total number of pages / number of pages per page can be obtained by rounding up to the nearest whole number.
There are various ways to do it, but if you implement the above as it is, it looks like this.
int totalSize = 30;
double pageSize = 10.0;
int totalPage = (int) Math.ceil(totalSize / pageSize);
System.out.println(totalPage);
>> 3
int totalSize = 35;
double pageSize = 10.0;
int totalPage = (int) Math.ceil(totalSize / pageSize);
System.out.println(totalPage);
>> 4
int totalSize = 40;
double pageSize = 10.0;
int totalPage = (int) Math.ceil(totalSize / pageSize);
System.out.println(totalPage);
>> 4
int totalSize = 41;
double pageSize = 10.0;
int totalPage = (int) Math.ceil(totalSize / pageSize);
System.out.println(totalPage);
>> 5
Math # ceil
is rounded up, but the number of cases per page is defined as double so that a decimal point will appear when dividing.
The return value is double, but I don't need the decimal point, so I cast it to int. If it is a primitive type, non-null is guaranteed, but if something like "extract only the integer part of Double" is not an object, it will be a little unnatural.