Hi,
Decimal arithmetic in velocity should always returns a decimal - except when both sides of a division are an integer. This was agreed upon after a long long discussion last year. The basic rationale is backwards compatibility. The most important use case for this behavior is column arithmetic. I did an informal survey of dozens of internal Velocity apps at the time and found several examples (similar to JohnE's app) where column arithmetic required integers.
I just tested this and found out that this is not how Velocity is actually behaving. Apparently the patch committer went ahead and ignored that hard-won consensus opinion and slipped in the decimal divided by decimal equals decimal result.
I'll fix this issue tonight. Thanks for reporting this.
Best, WILL
----- Original Message ----- From: "Shinobu Kawai" <[EMAIL PROTECTED]>
To: "Velocity Users List" <velocity-user@jakarta.apache.org>
Sent: Monday, April 11, 2005 5:48 PM
Subject: Re: Problem with decimal in most recent snapshot
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/[EMAIL PROTECTED]
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 <[EMAIL PROTECTED]>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]