subtraction is not working with velocity template

2019-02-25 04:56发布

问题:

I have this code in velocity html

<html>



#set ($Total1 = 0.0)
#set ($Total2 = 3.0)
#set ($Total3 = $Total2 -$Total1)
$Total3

</html>

The $Total3 is not getting displayed. In fact the subtraction is not working. Can anyone please help me on this

回答1:

I just tried that example in Velocity 1.6 and it worked fine.

Two possible things that might be causing problems.

(1) Your example is not copied correctly. If a dash is next to an identifier, it becomes part of the identifier. So this example would fail, since the "-" sign is actually part of the Total2 identifier.

#set ($Total3 = $Total2- $Total1)

(2) You are using a very old version of Velocity. Floating point numbers were legal syntax beginning with Velocity 1.5. (The current version is 1.7). Before that point, integers were the only number type allowed.



标签: velocity