本文共 777 字,大约阅读时间需要 2 分钟。
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://yhzvi.baihongyu.com/