首页 > 编程语言 > 详细

Java 数字转百分比%

时间:2015-08-05 12:05:54      阅读:284      评论:0      收藏:0      [点我收藏+]

java 将数字转成百分比 (%)float integer double 等等 


java.text.NumberFormat percentFormat =java.text.NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(2); //最大小数位数 
percentFormat.setMaximumIntegerDigits(int);//最大整数位数 
percentFormat.setMinimumFractionDigits(2); //最小小数位数 
percentFormat.setMinimumIntegerDigits(int);//最小整数位数 
percentFormat.format(float)//自动转换成百分比显示.. 

也可以用: 
1) java.text.DecimalFormat percentFormat =new java.text.DecimalFormat(); 
   percentFormat.format(long/double/float); 
   但这个我不知道怎样控制小数位数. 
2) 也可用bean-write标签,<bean:write name="post" property="rate" format="####0.00%"/>

 

Java 数字转百分比%

原文:http://www.cnblogs.com/iamcui/p/4704031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!