Java中設置百分數保留兩位小數


 1 public class Percent { 
 2 @Test 
 3 public void getPercent() { 
 4 double d1 = 24.58D; 
 5 double d2 = 30.86D; 
 6 NumberFormat nt = NumberFormat.getPercentInstance(); 
 7 //設置百分數保留兩位小數 
 8 nt.setMinimumFractionDigits(2); 
 9 System.out.println(nt.format(d1 / d2)); 
10 } 
11 } 

 


免責聲明!

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



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