velocity模板小数点截断两位

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



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值