简体   繁体   English

速度向上或向下舍入

[英]Rounding Up or Down in Velocity

Simple question: Can I do the equivalent of Math.ceil and Math.floor in a Velocity template?简单的问题:我可以在 Velocity 模板中做相当于 Math.ceil 和 Math.floor 的操作吗? From what I could find I would have to use MathTool , but that doesn't seem to have what I want.据我所知,我必须使用MathTool ,但这似乎没有我想要的。

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.我想说您可以使用MathTool.roundToInt()并加/减 1,但也应该可以为 object 提供您可能需要的方法。

Also have a look at Velocity Tools 2.0 whose MathTool has methods floor() and ceil().还可以查看Velocity Tools 2.0 ,其MathTool具有方法 floor() 和 ceil()。

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.我推荐 Tools 2.0 MathTool 以获得最大的类型灵活性,但 Velocity Engine 的 1.6+ 通过将 class 本身放入上下文来支持 static 方法。 So the quick and easy solution is:因此,快速简便的解决方案是:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM