Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert in Expression Language double or float value to int without round off?

 
Abhishek Anne
Greenhorn
Posts: 4
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, do all these arithmetic calculations in java class.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Anne
Greenhorn
Posts: 4
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7772
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The expression you are looking for is this:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using doubles to begin with?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic