没有 MathTools 的 Apache velocity Round 或 Ceil
Apache velocity Round or Ceil without MathTools
在第三方应用程序中使用 Apache Velocity。无法使用 MathTools。我想对 x/8
的值进行四舍五入或取整
1/8 = 1
8/8 = 1
9/8 = 2
16/8 = 2
19/8 = 3
等等
我可以使用的内部速度是 Modulo %
和基本的 * / + -
大多数在线答案都有转换,我也不能使用
这并不是 Velocity 特有的,那是整数运算。无论如何,您可以通过在除法之前加 7 来模拟 Ceil,并根据剩余的部分取 floor 或 ceiling 来模拟 Round。
#set($ceil = ($n + 7) / 8)
#set($round = $n / 8)
#if($n % 8 > 4) #set($round = $round + 1) #end
在第三方应用程序中使用 Apache Velocity。无法使用 MathTools。我想对 x/8
的值进行四舍五入或取整1/8 = 1
8/8 = 1
9/8 = 2
16/8 = 2
19/8 = 3
等等
我可以使用的内部速度是 Modulo %
和基本的 * / + -
大多数在线答案都有转换,我也不能使用
这并不是 Velocity 特有的,那是整数运算。无论如何,您可以通过在除法之前加 7 来模拟 Ceil,并根据剩余的部分取 floor 或 ceiling 来模拟 Round。
#set($ceil = ($n + 7) / 8)
#set($round = $n / 8)
#if($n % 8 > 4) #set($round = $round + 1) #end