本站首页    管理页面    写新日志    退出


«December 2025»
123456
78910111213
14151617181920
21222324252627
28293031


公告
本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:210
评论数量:205
留言数量:-19
访问次数:929237
建立时间:2007年5月10日




[界面和模板语言]freemarker内置数字标签
文章收藏,  网上资源,  软件技术,  电脑与网络

李小白 发表于 2008/12/5 10:41:25

c把一个数字转换成字符串时,使用的java语言使用的数字格式(跟Locale相关),这样是为了符合人类的习惯.比如300000会显示成300,000.如果我们把这个数字作为表单的一个域值放进数据库或者在javascript中使用时,需要再转换成适合计算机输入的格式.这个标签用来输出数字(例如用${x?c}替换${x})防止这种格式转换. string(当跟一个数字一起使用时)将一个数字转换成字符传,使用默认的格式,当然也可以明确的要使用的指定数字或者日期格式.有3中预置格式:number,currency,percent.你可以像下面一样使用表达式: 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> <#assign answer=42/>${answer}${answer?string} <#-- the same as ${answer} -->${answer?string.number}${answer?string.currency}${answer?string.percent} 如果使用的是的US 英语,输出是 500)this.width=500'> 424242$42.004,200%输出前3个是一样的,因为前2个使用默认的格式,在这里是"number".你可以改变默认设置 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> <#setting number_format="currency"/><#assign answer=42/>${answer}${answer?string} <#-- the same as ${answer} -->${answer?string.number}${answer?string.currency}${answer?string.percent} 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'>将会输出: $42.00$42.0042$42.004,200% 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'>除了3种预置的格式,你还可以使用java小数格式化语法,即可以像预置格式一样使用,也可以像明确的格式选择器: 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> <#setting number_format="0.###E0"/> ${1234} ${12345?string("0.####E0")} 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 输出: 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 1.234E3 1.2345E4 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 注意:你也可以${answer?string("number")},跟${answer?string.number}.是一样的。 注意:数字格式是LOCALE敏感的: 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> <#setting locale="en_US"> US people writes: ${12345678?string(",##0.00")} <#setting locale="hu"> Hungarian people writes: ${12345678?string(",##0.00")} 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 输出: 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> US people writes: 12,345,678.00 Hungarian people writes: 12 345 678,00 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'>


阅读全文(3699) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.785 second(s), page refreshed 144811542 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号