freemarker中处理页面自动四舍五入问题
2013-12-13 16:12
357 查看
在开发中很容易忽视一点,输入一个值(可能是小数),输出时如果不做处理,就很容易出现
隐形的BUG。比如,如果从数据库取出一个0.22的数值,一般的输出${x?if_exists?html},
这时是显示0,而不是0.22。
应该写成${x?if_exists?string.number} 或者 ${x?if_exists.toString()?html}
下面就是关于数字的具体介绍:
=======================================================================
<#assign x=42>
${x}
${x?string} <#-- the same as ${x} -->
${x?string.number}
${x?string.currency}
${x?string.percent}
If your locale is US English, this will certainly produce:
42
42
42
$42.00
4,200%
=======================================================================
<#setting number_format="currency">
<#assign x=42>
${x}
${x?string} <#-- the same as ${x} -->
${x?string.number}
${x?string.currency}
${x?string.percent}
Will now output:
$42.00
$42.00
42
$42.00
4,200%
=======================================================================
<#assign x = 1.234>
${x?string("0")}
${x?string("0.#")}
${x?string("0.##")}
${x?string("0.###")}
${x?string("0.####")}
${1?string("000.00")}
${12.1?string("000.00")}
${123.456?string("000.00")}
${1.2?string("0")}
${1.8?string("0")}
${1.5?string("0")} <-- 1.5, rounded towards even neighbor
${2.5?string("0")} <-- 2.5, rounded towards even neighbor
${12345?string("0.##E0")}
outputs this:
1
1.2
1.23
1.234
1.234
001.00
012.10
123.46
1
2
2 <-- 1.5, rounded towards even neighbor
2 <-- 2.5, rounded towards even neighbor
1.23E4
=======================================================================
<#setting number_format="0.##">
${1.234}
outputs this:
1.23
隐形的BUG。比如,如果从数据库取出一个0.22的数值,一般的输出${x?if_exists?html},
这时是显示0,而不是0.22。
应该写成${x?if_exists?string.number} 或者 ${x?if_exists.toString()?html}
下面就是关于数字的具体介绍:
=======================================================================
<#assign x=42>
${x}
${x?string} <#-- the same as ${x} -->
${x?string.number}
${x?string.currency}
${x?string.percent}
If your locale is US English, this will certainly produce:
42
42
42
$42.00
4,200%
=======================================================================
<#setting number_format="currency">
<#assign x=42>
${x}
${x?string} <#-- the same as ${x} -->
${x?string.number}
${x?string.currency}
${x?string.percent}
Will now output:
$42.00
$42.00
42
$42.00
4,200%
=======================================================================
<#assign x = 1.234>
${x?string("0")}
${x?string("0.#")}
${x?string("0.##")}
${x?string("0.###")}
${x?string("0.####")}
${1?string("000.00")}
${12.1?string("000.00")}
${123.456?string("000.00")}
${1.2?string("0")}
${1.8?string("0")}
${1.5?string("0")} <-- 1.5, rounded towards even neighbor
${2.5?string("0")} <-- 2.5, rounded towards even neighbor
${12345?string("0.##E0")}
outputs this:
1
1.2
1.23
1.234
1.234
001.00
012.10
123.46
1
2
2 <-- 1.5, rounded towards even neighbor
2 <-- 2.5, rounded towards even neighbor
1.23E4
=======================================================================
<#setting number_format="0.##">
${1.234}
outputs this:
1.23
相关文章推荐
- FreeMarker的FTL页面中include引用UTF-8文件导致错位的问题处理
- FreeMarker的FTL页面中include引用UTF-8文件导致错位的问题处理
- FreeMarker的FTL页面中include引用UTF-8文件导致错位的问题处理
- FreeMarker的FTL页面中include引用UTF-8文件导致错位的问题处理
- shiro +springmvc+freemarker session问题处理 shiro无法记录登陆前页面问题
- Jfinal使用Freemarker配置处理NULL、重起生效等问题
- Ext grid中单元格会自动处理Xml格式问题,对尖括号的转义
- 在使用showModalDialog时struts1提交表单,弹出新页面问题处理
- ScrollView嵌套GridView或者ListView的时候,页面自动滚动到GridView或者ListView所在位置的问题
- iis报错:404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
- VB 表格导出Excel 自动处理‘0’的问题
- 一个自动生成关键字索引页面的比处理文件
- 处理Oracle XE无法打开主页面的问题
- 关于js中处理时间戳和图片预加载的问题自动提交
- sql server2005 jdbc解决自动增长列统一处理问题
- Shiro中Session过期页面跳转回登录页面处理问题
- 实现提交页面后滚动条自动移动问题
- 数据库同步自动断开问题的处理
- Silverlight Xap包、配置文件修改后不能自动更新问题处理方式总结
- 如何处理404页面的问题