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 }
