2013-07-25 66 views

回答

4

的DecimalFormat的這個實例添加到您的方法的頂部:

DecimalFormat three = new DecimalFormat("#,##0.000"); // will display numbers separated by commas every three digits to the left of the decimal, and will round it to three decimal places. No more, no less. 

// the three zeros after the decimal point above specify how many decimal places to be accurate to. 
// the zero to the left of the decimal place above makes it so that numbers that start with "0." will display "0." vs just "." If you don't want the "0.", replace that 0 to the left of the decimal point with "#" 

然後,調用實例 「三化」,並通過你的雙顯示時的值:

double PV = 154055.054847215; 
display.setText(three.format(PV)); // displays 1,540,055.055 
1

試試這個:

DecimalFormat formatter = new DecimalFormat("#,###.00"); 

System.out.println(formatter.format(PV)); 

Source

1
String s = String.format(%,.2f, PV); 

System.out.println(s); 
相關問題