Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding Up or Down in Velocity

Simple question: Can I do the equivalent of Math.ceil and Math.floor in a Velocity template? From what I could find I would have to use MathTool, but that doesn't seem to have what I want.

like image 572
Alex Beardsley Avatar asked Apr 29 '11 20:04

Alex Beardsley


2 Answers

I'd say you could work with MathTool.roundToInt() and adding/subtracting 1, but it should also be possible to provide an object with your methods that might provide what you need.

Also have a look at Velocity Tools 2.0 whose MathTool has methods floor() and ceil().

like image 82
Thomas Avatar answered Nov 11 '22 05:11

Thomas


I recommend the Tools 2.0 MathTool for greatest type flexibility, but Velocity Engine's 1.6+ support static methods by putting the class itself into the context. So the quick and easy solution is:

context.put("Math", Math.class);

$Math.ceil($foo) $Math.floor($bar)

like image 26
Nathan Bubna Avatar answered Nov 11 '22 06:11

Nathan Bubna