I use Expression Language (EL) in JSP.
<c:set var="noOfPages" value="${numItems/itemsPerPage}" /> <fmt:formatNumber var="noOfPagesRounded" value="${noOfPages}" maxFractionDigits="0" /> <c:if test="${(numItems % itemsPerPage) > 0}"> <c:set var="noOfPages" value="${noOfPagesRounded + 1}"/> </c:if >
As you can see, I calculate no. pages required to display x no. results per page.
This does not work all the time, because in line 2 the tag formatNumber rounds the results of my division, which I do not want to round.
i.e. for 73 records of 20 per page you need 4 pages, but I get the result 5, because in line 2 it is rounding the result 3.65 to 4, but I want noOfPagesRounded=3 .
How do I convert a float or double value to int without rounding?
source share