I am using 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 see I am calculating no. of pages required to display x
no. of results per page.
This doesn't work all time since at line 2 i.e. formatNumber
tag is rounding of my division results, which I don't want to get rounded off.
i.e. for 73 records 20 per page needs 4 pages but I am getting result 5, because at line 2 it is rounding of result 3.65 to 4 but I want noOfPagesRounded=3
.
How should I convert float
or double
value in int
without rounding off?
If you want noOfPagesRounded to be set to floor(noOfPages) then try this (a floor function is not available in EL):
<fmt:formatNumber var="noOfPagesFloored" value="${noOfPages-(noOfPages%1)}" maxFractionDigits="0" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With