15.1. 数学特征

Velocity 有一些内建的数学功能,可以使用set指令用在模版中。下面的共识分别演示了加减乘除运算:

#set( $foo = $bar + 3 )
#set( $foo = $bar - 4 )
#set( $foo = $bar * 6 )
#set( $foo = $bar / 2 )

当进行除法运算时,结果将会是整数。When a division operation is performed, the result will be an integer. 余数则可以通过模(%)运算获得。

#set( $foo = $bar % 5 )

在Velocity 中,只有整数可以进行数学运算;如果执行非整数的数学运算,将被记录下来,并返回null 。