Java 數字轉百分比%


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%"/>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM