• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, do all these arithmetic calculations in java class.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 (https://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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The expression you are looking for is this:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using doubles to begin with?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic