<fmt:formatNumber 講解

 來源:http://wabe033.spaces.live.com/blog/cns!39fefd640e2bb5ab!882.entry

JSTL fmt:formatNumber 數字、貨幣格式化

<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格式化輸出:
DecimalFormat df = new DecimalFormat("格式");
String fmt =df.format(double);
符號                  意義
0                     一個數位
#                     一個數位,前導零和追尾零不顯示
.                      小數點分割位置
,                     組分隔符的位置
-                      負數前綴
%                    用100乘,並顯示百分號
其他任何符號    在輸出字符串中包括指定符號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章