double PV = 154055.054847215
如何将其显示为 1,540,055.055 ?
将此 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
尝试这个:
DecimalFormat formatter = new DecimalFormat("#,###.00");
System.out.println(formatter.format(PV));
String s = String.format(%,.2f, PV);
System.out.println(s);