您的位置:首页 > Web前端 > JavaScript

JSTL fmt:formatNumber 数字、货币格式化

2010-01-25 19:16 405 查看

JSTL fmt:formatNumber 数字、货币格式化

关键字: fmt:formatnumber

Java代码

<fmt:formatNumber value=
"12"
type=
"currency"
pattern=
"$.00"
/>
//-- $12.00

<fmt:formatNumber value="12"
type=
"currency"
pattern=
"$.0#"
/>
//-- $12.0

<fmt:formatNumber value="1234567890"
type=
"currency"
/>
//-- $1,234,567,890.00(那个货币的符号和当前web服务器的 local 设定有关)

<fmt:formatNumber value="123456.7891"
pattern=
"#,#00.0#"
/>
// -- 123,456.79

<fmt:formatNumber value="123456.7"
pattern=
"#,#00.0#"
/>
//-- 123,456.7

<fmt:formatNumber value="123456.7"
pattern=
"#,#00.00#"
/>
// -- 123,456.70

<fmt:formatNumber value="12"
type=
"percent"
/>
//-- 1,200% (type 可以是currency、 number、 和percent)。

<fmt:formatNumber value="12" type="currency" pattern="$.00"/> //-- $12.00

<fmt:formatNumber value="12" type="currency" pattern="$.0#"/> //-- $12.0

<fmt:formatNumber value="1234567890" type="currency"/> //-- $1,234,567,890.00(那个货币的符号和当前web服务器的 local 设定有关)

<fmt:formatNumber value="123456.7891" pattern="#,#00.0#"/>// -- 123,456.79

<fmt:formatNumber value="123456.7" pattern="#,#00.0#"/> //-- 123,456.7

<fmt:formatNumber value="123456.7" pattern="#,#00.00#"/>// -- 123,456.70

<fmt:formatNumber value="12" type="percent" /> //-- 1,200% (type 可以是currency、 number、 和percent)。


java格式化输出:

Java代码

DecimalFormat df =
new
DecimalFormat(
"格式"
);

String fmt =df.format(double
);

DecimalFormat df = new DecimalFormat("格式");
String fmt =df.format(double);


符号 意义

0 一个数位

# 一个数位,前导零和追尾零不显示

. 小数点分割位置

, 组分隔符的位置

- 负数前缀

% 用100乘,并显示百分号

其他任何符号 在输出字符串中包括指定符号
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: