Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subtraction is not working with velocity template

Tags:

velocity

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

like image 288
SHP Avatar asked Dec 16 '22 13:12

SHP


1 Answers

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.

like image 77
Will Glass Avatar answered May 11 '23 04:05

Will Glass