| « | December 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | |
| 公告 |
| 本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。 |
| 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'> |
|
|