velocity模板小數點截斷兩位
阿新 • • 發佈:2019-02-14
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?
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.