subtraction is not working with velocity template

2019-02-25 04:46发布

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

标签: velocity
1条回答
再贱就再见
2楼-- · 2019-02-25 05:21

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.

查看更多
登录 后发表回答