| Author |
How to convert in Expression Language double or float value to int without round off?
|
Abhishek Anne
Greenhorn
Joined: Sep 05, 2011
Posts: 4
|
|
I am using Expression Language (EL) in JSP.
As you see I am calculating no of pages required to display x no of results per page.
This doesnt work all time since at line 2 ie formatNumber tag is rounding of my division results.(which i dont want to get round)
ie for 73 records 20 per page needs 4 pages buts i m 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 round of?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
Please, do all these arithmetic calculations in java class.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Yes. Remember, keep the JSP pages as dumb as possible. Do all the complex work in the page controller before the JSP is even invoked.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Abhishek Anne
Greenhorn
Joined: Sep 05, 2011
Posts: 4
|
|
Hi Seetharaman and Bear,
It is standard to keep all calculations on controller class but there is some dependency that to make some calculations on page itself.
(n no of controller calling this page also I have no access to few controller classes).
Thanks
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4118
|
|
|
If you really can't follow the earlier advice to do the calculation prior to the JSP, then write a Java class, say PageCalculator, then use jsp:useBean (http://www.coderanch.com/t/289559/JSP/java/JSTL-create-bean) to create an instance, then c:set to set properties of the PageCalculator bean (e.g. itemCount and itemsPerPage), then c:out to display the result of the calculation, say from a method on PageCalculator called pageCount.
|
Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
The expression you are looking for is this:
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Why are you using doubles to begin with?
|
 |
 |
|
|
subject: How to convert in Expression Language double or float value to int without round off?
|
|
|