velocity 模板能够对数值进行formate,现在有个需求是希望能够小数点保留两位,
坑爹的文档,就给了最基本的用法,还是我大stackoverflow威武,一查一个准:
上代码:
$number.format("#0.00", $val)
附原文:
************************************************
I want to convert
23.59004 to 23.59
35.7 to 35.70
3.0 to 3.00
9 to 9.00
Please tell me how can I do it in velocity template? I searched a lot for this and found that I can use velocity tools, but there are no examples related to it? and can i use velocity tools in templates?
answer:
Velocity tools are expected to be used in Velocity templates; essentially they are objects added to the variables available in a template so that you can use $numberTool.format("#0.00", $val)
or similar. If none of the available tools don't fit your needs, simply create a POJO and add it to the template.
http://stackoverflow.com/questions/8820240/how-to-format-numbers-in-velocity-templates
参考: http://www.cnblogs.com/opaljc/archive/2012/04/20/2459685.html
官方文档:https://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/NumberTool.html