wood burning stoves*
The moose likes JSP and the fly likes How to convert in Expression Language double or float value to int without round off? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to convert in Expression Language double or float value to int without round off?" Watch "How to convert in Expression Language double or float value to int without round off?" New topic
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: 60046
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 4419
    
    5

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]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

The expression you are looking for is this:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Why are you using doubles to begin with?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert in Expression Language double or float value to int without round off?
 
Similar Threads
Spring Controller receive correct data from button when "apply" button is clicked
Making precisions in calculations with JSTL
c:set adding a newline
how to overwrite a request param?
Round number to nearest quarter