JSTL formatNumber 數字、貨幣格式化

 標籤引用:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>

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

<fformatNumber value="12" type="currency" pattern="$.00"/> -- $12.00

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

<f:formatNumber value="1234567890" type="currency"/> -- $1,234,567,890.00(那個貨幣的符號和當前web服務器的 local 設定有關)

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

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

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

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

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

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