博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
velocity模板小数点截断两位
阅读量:4129 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
2019年哪些外快收入可达到2万以上?
查看>>
【JavaScript 教程】标准库—Date 对象
查看>>
前阿里手淘前端负责人@winter:前端人如何保持竞争力?
查看>>
【JavaScript 教程】面向对象编程——实例对象与 new 命令
查看>>
我在网易做了6年前端,想给求职者4条建议
查看>>
SQL1015N The database is in an inconsistent state. SQLSTATE=55025
查看>>
RQP-DEF-0177
查看>>
Linux查看mac地址
查看>>
Linux修改ip
查看>>
MySQL字段类型的选择与MySQL的查询效率
查看>>
Java的Properties配置文件用法【续】
查看>>
JAVA操作properties文件的代码实例
查看>>
IPS开发手记【一】
查看>>
Java通用字符处理类
查看>>
文件上传时生成“日期+随机数”式文件名前缀的Java代码
查看>>
Java代码检查工具Checkstyle常见输出结果
查看>>
北京十大情人分手圣地
查看>>
Android自动关机代码
查看>>
Android中启动其他Activity并返回结果
查看>>
2009年33所高校被暂停或被限制招生
查看>>