How to do integer arithmetic in JSTL?

I have a foreach loop where I am presenting database results and showing them to the user in 'chunks' (similar to search engine). At the bottom, I also want to have a line of page numbers which refer to the chunks (e.g. 1 2 3 4 ...), and this is where I am having a problem. An integer division in the c:out or in the forEach loop seems to switch JSTL into floating point arithmetic mode, and that results in the <c:out> below producing non-integer values: 1.0 2.0 3.0 .... Is there a way to force it to do integer arithmetic? Or, possibly to format what c:out produces to drop the ".0" part?
Here's the code:
        <c:forEach var="index"
                  begin="0" end="${searchResultSize}" step="${chunkSize}">
                    <!-- ...snip... build anchor tag ... -->
                    <c:out value="${(index/chunkSize)+1}"/></a>
        </c:forEach>I modified the above to take the calculation our of the c:out, but had same result (1.0 2.0 3.0, etc):
            <c:forEach var="index"
                  begin="0" end="${searchResultSize/chunkSize}" step="1">
                     <!-- ...snip... build anchor tag ... -->
                    <c:out value="${index+1}"/></a>
            </c:forEach>

To format numbers you use the format tag library, also included with the JSTL
<fmt:formatNumber value="${(index/chunkSize)+1}" type="number" maxFractionDigits="0" />
Cheers,
evnafets

Similar Messages

  • Integer arithmetic

    Is there an authoritative specification of the precise rules for arithmetic in ActionScript 3 somewhere?
    I need to do some exact integer arithmetic modulo 2^32, such that, e.g. this will output 0 then -1 (that being the least significant 32 bits of the true mathematical result of the multiplications):
    var base:int = 1<<30 ;
    for( var i:int=0; i<2; i++ ) {
      var a:int = base+i ;
      var b:int = base-i ;
      trace(int(a*b));
    According to ECMAScript arithmetic, the multiplication would produce an IEEE-754 double-precision result, which for both times round the loop would be rounded to 2^60 exactly. When that result is converted to an int (again following ECMAScript rules), we get 0 in both cases.
    Of course, ECMAScript doesn't know about AS3's int type, and in practical experiments I do indeed get 0 and -1. I'm happy with that, but I'm worried that this may just be due to the whims of the VM at runtime rather than something I can rely on. For example, I could imagine that it would use integer arithmetic in JITted code but fall back to ECMAScript arithmetic in "non-hotspot" interpreted mode. The generated bytecode just uses a generic "multiply" instruction, so a bytecode interpreter would need to look ahead to figure out that it is alright to use integer multiplication. For all I know, it might even depend on whether the Flash player that runs the code is a 32-bit or a 64-bit version.
    I have not been able to convince the AS3 compiler (from the open source Flex SDK 4.1.0) generate the "multiply_i" instruction.
    So, what's the actual rules? Is it just luck that I get the correct result?

    Um, I know that. My question is how can I be certain to get a true int multiplication that preserves the 32 least significant bits of the result and throws away the high ones, instead of a Number multiplication that preserves the most significant 53 bits of the result and throws away the low ones.
    After some more investigation I've found that Alchemy compiles a multiplication of C "unsigned"s (which by specification must work modulo 2³²) into just
      public var i0:int, i1:int, ...
      i0 = (i1 * i0)
    in Actionscript, eventually producing the same "multiply" bytecode in ABC as I get myself. So perhaps this really is a safe way to do integer multiplication. On the other hand, Alchemy does not have a shining reputation for stability and bug-freedom either ...

  • How to use this method in JSTL?help me please!

    I know I can use "<C:set >" like as
    <c:set var="clabel3" value="${portalCustomizeBean.portalPage}"/> ,
    but now I want to use one method of portalCustomizeBean object not a attribute of it !!!!!
    who would tell me how to use?
    this is wrong in my code:
    <c:set var="clabel" value="${portalCustomizeBean.currentPageLabel}"/>
    <c:set var="clabel3" value="${portalCustomizeBean.toEntitiesExceptSpaceEscape(clabel)}"/>
    but how to use "toEntitiesExceptSpaceEscape" method in JSTL?????

    Why can't you just assign the method's return value to a variable and then print that? A bit of scriptlet code will do the trick. (As much as we all hate to use scriptlet code.)
    I believe you'll be able to do what you want in the 1.1 standard JSTL, but for now this will suffice. - MOD

  • How to use Java Beans In JSTL?

    Hi
    I want to know how to use Java bean in JSTL
    please explain this with giving any one example.
    Thanks-
    Swapneel

    A bean is obtain by <jsp:useBean> tag nd once bean is obtained we can get its property by using getProperty tag.

  • How to address seesion attribute with JSTL?

    Hi there,
    In login, I have set session attribute of userid, how can I get it in JSTL?
    TIA
    Wolf

    Got it.
    sessionScope.attributename
    Wolf

  • How to add integer value of two buttons?

    how to add integer value of two buttons (any button) in VI and display it in output text box? i have attached example program, but i know its wrong.. please help
    Solved!
    Go to Solution.
    Attachments:
    add.vi ‏8 KB

    thanks for reply. i am trying to assign an integer value to a button and the button should send the assigned integer value to TCP/IP write, only when the button is pressed. i am able to send data using string control (as shown in the attachment) but i want to replace it with several buttons. for example, if i enter 2 in string control, this data will be sent to a robot (robot has wifi card)  through tcp/ip protocol, it moves front. 3 will make it to move back, 8 is left, 6 is right. this numeric data is already burnt into blackfin processor of the robot. so just by entering numbers in labview can make my robot move in specified direction. can you please help me to create a button with value and convert it into string and send it to tcp/ip write. this should happen only when the button is pressed. because, if i enter numbers in string control, it dosent looks good..... if i have buttons... i think my VI will look good and hitech.
    Attachments:
    robo.vi ‏9 KB

  • How to return integer used wit DMBS_SQL as ref cursor ?

    I am trying to return a ref cursor form a procedure to be used by xsql to output hierarchical XML.
    I created the query using the DBMS_SQL package, did an OPEN_CURSOR and then PARSE.
    Can I, and if so how, return the integer from the PARSE as a ref cursor out of my procedure ? According to the docs the integer in the PARSE is the ID number for a cursor.
    thanks,
    Reinier

    I suspect that you are a little confused. I doubt that what you are asking for is what you really need. I believe you want the contents of a ref cursor, not an integer that is the cursor id. Since you are using Oracle 8i, as mentioned in your other post, you don't need DBMS_SQL; You just need to open a ref cursor dynmacially. Please see my response to your other post:
    Re: Error while compiling form in AS 10g  deployed on Linux

  • How to use else if  in JSTL

    Can any one tell me ,
    How to use else if in JSTL,
    For example,
    if(a > b){
    // code block
    }else if(b > c){
    // code block
    }else{
    // code block
    Shall i use like following,
    <c:choose>
    <c:when test=' "${ a > b }" '>
    </c:when>
    <c:when test=' "${ b > c }" '>
    </c:when>
    <c :otherwise>
    </c:otherwise>
    </c:choose>
    this JSTL code is correct or not?..
    Thanks in advance
    Deenu

    Deenu wrote:
    <c:choose>
    <c:when test=' "${ a > b }" '>
    </c:when>
    <c:when test=' "${ b > c }" '>
    </c:when>
    <c :otherwise>
    </c:otherwise>
    </c:choose>
    this JSTL code is correct or not?..Remove the single quotes and it's fine.
    It is not clear if it is applicable on your functional requirement, but it is good to know that EL supports conditional statements.

  • How to charge integer to object

    hi:
    the program just like below, the Fast and Slow is define by meself.
    public class Fast {
    private Vector vecArr = new Vector();
    public void push(Object elem){
    vecArr.addElement(elem);
    Fast sortFast=new Fast();
    Slow sortSlow=new Slow();
    public void test(){
    for(int i=32;i<=1024;i=i+i){
    for(int j=i;j>=1;j++){
    sortFast.push(j);
    sortSlow.push(j);
    my program alway stop at sortFast.push(j);
    the compile error is
    "cannot resolve symbol
    symbol : method push (int)
    location: class Fast
    sortFast.push(j);
    ^
    does somebody know how to change integer to object?
    Thanks a lot!

    here is how:
    int mySimpleInt = 5;
    Integer myIntegerObject = new Integer(mySimpleInt);

  • How to use integer as char

    Hi!
    I have an integer (5). And now i want to use it as char ('5').
    I have already tried (char)(5) but that returns me a strange char--char with unicode (5).
    How should i change the type of variable?
    Thanks

    The following might be logical (not practical).
    char c = ((Integer.toString(5)).toCharArray()[0]);

  • How to access XML attributes with JSTL

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

  • How to put integer in a file

    Who knows how to record data in the file that after recording, it will not be'abrakadabra', but very distinctive
    files for example with integer.
    Thank you in advance

    Save as strings:
    DataOutputStream.writeUTF(String)

  • Is there any way to use Integer.parseInt using jstl

    Hi
    actually i m getting a string in a varible i need to convert it to int so that i can use it for further calculation.
    so plz tell how to do that...
    thanks

    The exception clearly states the variable isn't a valid number. Print out the value and see what it is.
    And no, you can't set the 'JSTL variable' for the simple reason that there are no 'JSTL variables' ( at least none that are public ). You're probably thinking of the EL. And no, you can't do anything there either.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How to display integer in the JtextField?

    Dear All
    I need your guidance and your advise on the following.
    I am creating an applet and I don't know how to display the integer which I have.
    Basically, i need to disply the following into a JtextField.
    int d1 = (int) (Math.random() * 6) + 1;
    int d2 = (int) (Math.random() * 6) + 1;
    I have two textfield which i name them textField1 and textField2.
    But how can I generate my random value obtained from the above and display it inside the text field?

    SummerCool wrote:
    Dear All
    I need your guidance and your advise on the following.
    I am creating an applet and I don't know how to display the integer which I have.
    Basically, i need to disply the following into a JtextField.
    int d1 = (int) (Math.random() * 6) + 1;
    int d2 = (int) (Math.random() * 6) + 1;
    I have two textfield which i name them textField1 and textField2.
    But how can I generate my random value obtained from the above and display it inside the text field?
    textField1 .setText(""+d1);
    textField2 .setText(""+d2);

  • How to use integer in case structure on FPGA

    Hi there,
    I was trying to use a case structure on FPGA module. The input to case selector terminal could be arbitrary integer like 0x1EEE or 0x2000 or 0x3FFF. Since I cannot find integer-string conversion on FPGA, how can I do it? Thanks

    Hello!
    If you want to create a case structure to handle arbitrary integer values, you can always use the decimal representation of the hex value (i.e. instead of 0x00FF, use 255).  If you want to create cases for the hex values, you can right-click on the case structure, and choose Radix>>Hex.  You should notice that all cases are now preceded with an 'x' to denote hex values.  This will allow you to create cases called x00FF, which sounds like what you're looking for.
    Cheers,
    Matt Pollock
    National Instruments

Maybe you are looking for

  • Transfer Table View from R/3 to Sap BW? How to Replicate DS form R/3 to Bw?

    Dear Friends , I have a requrement where I need to transfer a Table view from SAP R/3 to SAP BW System. I have made view , In RSO2 identified Data source In RSA3 Did the data extracion process. I need proceeding steps to follow in SAP BW 1. Replicate

  • Can't connect to wireless printer from Mac

    I have 2 wireless printers.  My Macs can connect to one, but can not find the other.  My PCs can connect to both just find.  The printer I can't connect to is a Lexmark 4650.  I'm running the install CD, but when it tries to find the printer, it does

  • Can't export from ECC report to Excel 2010 with more than 65 K Rows

    I see several posts about Excel 2007 and the 65K row limitation, but we are rolling out Office 2010 (Excel 2010) and find that it still will not allow download of more than 65,000 from an ECC report screen. Excel 2010 is supposed to handle over a mil

  • Extra event container element in BUS2203

    HI All, I have a standard workflow template WS10400002 which has some start condtions defined. If you check in the binding between event container --> workflow container, there is a extra element for "Gross Amount(USD)". Kindly let me know how we can

  • Restoring mail if its been in the trash can

    Hello there, I gotten an important mail piece in my mail box but I deleted it by mistake. When I went to go and look for it ... it wasn't there no more. Now my question comes to you to see if you can restore mail piece after its been lost or not?