You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Pierre Scemla <ps...@openpricer.com> on 2004/09/09 12:50:09 UTC

Integer division question

Hi,

I have the following el code in a jsp:
    length="${fn:length(myCollection) / 2}"
where length is an attribute of type String (I can't change it to 
Integer, this is an attribute of the Struts's iterate tag).

As fn:length() returns an integer and as 2 is an integer, I was 
expecting that the value for length would be "6" for instance,
but I got "6.0".
Is it an intended feature of the division operator of the jstl/el or is 
it a bug?

Pierre

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Integer division question

Posted by Kris Schneider <kr...@dotech.com>.
The EL was actually more inspired by ECMAScript and XPath than Java. In both
ECMAScript and XPath, division results in a floating-point value in accordance
with IEEE 754. If what you really want is a string representation of the number
without any fractional digits, you could use:

<fmt:formatNumber var="..." value="${fn:length(myCollection) / 2}"
pattern="#"/>

Quoting Pierre Scemla <ps...@openpricer.com>:

> Thanks for your answer.
> Does anybody know why they chose to do that instead of following the 
> behavior of the JLS?
> Is there a way to force the conversion to an Integer?
> 
> Pierre
> 
> Kris Schneider wrote:
> 
> >Per the JSP 2.0 Spec., both operands have been coerced to Double and then
> the
> >"/" operator has been applied.
> >
> >Quoting Pierre Scemla <ps...@openpricer.com>:
> >
> >  
> >
> >>Hi,
> >>
> >>I have the following el code in a jsp:
> >>    length="${fn:length(myCollection) / 2}"
> >>where length is an attribute of type String (I can't change it to 
> >>Integer, this is an attribute of the Struts's iterate tag).
> >>
> >>As fn:length() returns an integer and as 2 is an integer, I was 
> >>expecting that the value for length would be "6" for instance,
> >>but I got "6.0".
> >>Is it an intended feature of the division operator of the jstl/el or is 
> >>it a bug?
> >>
> >>Pierre

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Integer division question

Posted by Pierre Scemla <ps...@openpricer.com>.
Thanks for your answer.
Does anybody know why they chose to do that instead of following the 
behavior of the JLS?
Is there a way to force the conversion to an Integer?

Pierre

Kris Schneider wrote:

>Per the JSP 2.0 Spec., both operands have been coerced to Double and then the
>"/" operator has been applied.
>
>Quoting Pierre Scemla <ps...@openpricer.com>:
>
>  
>
>>Hi,
>>
>>I have the following el code in a jsp:
>>    length="${fn:length(myCollection) / 2}"
>>where length is an attribute of type String (I can't change it to 
>>Integer, this is an attribute of the Struts's iterate tag).
>>
>>As fn:length() returns an integer and as 2 is an integer, I was 
>>expecting that the value for length would be "6" for instance,
>>but I got "6.0".
>>Is it an intended feature of the division operator of the jstl/el or is 
>>it a bug?
>>
>>Pierre
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Integer division question

Posted by Kris Schneider <kr...@dotech.com>.
Per the JSP 2.0 Spec., both operands have been coerced to Double and then the
"/" operator has been applied.

Quoting Pierre Scemla <ps...@openpricer.com>:

> Hi,
> 
> I have the following el code in a jsp:
>     length="${fn:length(myCollection) / 2}"
> where length is an attribute of type String (I can't change it to 
> Integer, this is an attribute of the Struts's iterate tag).
> 
> As fn:length() returns an integer and as 2 is an integer, I was 
> expecting that the value for length would be "6" for instance,
> but I got "6.0".
> Is it an intended feature of the division operator of the jstl/el or is 
> it a bug?
> 
> Pierre

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org