velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <shinobu.ka...@gmail.com>
Subject Re: Problem with decimal in most recent snapshot
Date Tue, 12 Apr 2005 00:48:37 GMT
Hi JohnE,

> Basically I am getting a decimal when I should be getting an int with the following code
I use in production already:
> 
> #set ($colSize = ($jpPop.size() / 3) - 1)
> THE COLUMN SIZE IS $colSize
> 
> when colSize is printed out it gives a number like 6.3333333 when all values in this
calculation are integer.   I should get 6 as an int according to the documentation.

The User Guide says:
"When a division operation is performed between two integers, the
result will be an integer."
    http://jakarta.apache.org/velocity/user-guide.html#Math

The MathUtils#divide javadoc says:
"Integer-types will be returned as Integer-type if and only if the
modulo of the two numbers is 0."
    http://svn.apache.org/repos/asf/jakarta/velocity/trunk/src/java/org/apache/velocity/runtime/parser/node/MathUtils.java

They can't both be right.  If you consider backward compatibility, the
user guide should be correct.  But my mind says the javadoc is more
convenient...  Will?
cf. http://issues.apache.org/bugzilla/show_bug.cgi?id=25874
    http://mail-archives.eu.apache.org/mod_mbox/jakarta-velocity-dev/200501.mbox/%3c001201c5081a$68169710$6500a8c0@Apollo%3e

> From what I can see there is no way to make a float an integer either.  This too I would
imagine could be a problem.

For now, you can use the MathTool.
    http://jakarta.apache.org/velocity/tools/generic/MathTool.html#toInteger()

> I was hoping to push this into production tonight but it will have to wait till I can
figure out what to do with the potential affects this could have to the whole system or...it
gets resolved.

Which, I guess, makes a good reason for the user guide to be right.

Best regards,
-- Shinobu

--
Shinobu Kawai <shinobu.kawai@gmail.com>

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


Mime
View raw message