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

来源:互联网 发布:python 逻辑回归 编辑:程序博客网 时间:2024/05/29 00:30
Java代码 复制代码
  1. <fmt:formatNumber value="12" type="currency" pattern="$.00"/> //-- $12.00    
  2.   
  3. <fmt:formatNumber value="12" type="currency" pattern="$.0#"/> //-- $12.0    
  4.   
  5. <fmt:formatNumber value="1234567890" type="currency"/> //-- $1,234,567,890.00(那个货币的符号和当前web服务器的 local 设定有关)    
  6.   
  7. <fmt:formatNumber value="123456.7891" pattern="#,#00.0#"/>// -- 123,456.79    
  8.   
  9. <fmt:formatNumber value="123456.7" pattern="#,#00.0#"/> //-- 123,456.7    
  10.   
  11. <fmt:formatNumber value="123456.7" pattern="#,#00.00#"/>// -- 123,456.70    
  12.   
  13. <fmt:formatNumber value="12" type="percent" /> //-- 1,200% (type 可以是currency、 number、 和percent)。   

 

 

java格式化输出:

Java代码 复制代码
  1. DecimalFormat df = new DecimalFormat("格式");   
  2. String fmt =df.format(double);  

 

符号                  意义
0                     一个数位
#                     一个数位,前导零和追尾零不显示
.                      小数点分割位置
,                     组分隔符的位置
-                      负数前缀
%                    用100乘,并显示百分号
其他任何符号    在输出字符串中包括指定符号