如何以特定格式显示数字(Android Eclipse,Java)
如何将其显示为1540055.055?尝试以下操作:如何以特定格式显示数字(Android Eclipse,Java),java,android,eclipse,Java,Android,Eclipse,如何将其显示为1540055.055?尝试以下操作: double PV = 154055.054847215 将此DecimalFormat实例添加到方法顶部: DecimalFormat formatter = new DecimalFormat("#,###.00"); System.out.println(formatter.format(PV)); 然后,调用实例“三”,并在显示时传递双精度值: DecimalFormat three = new DecimalFormat("#
double PV = 154055.054847215
将此DecimalFormat实例添加到方法顶部:
DecimalFormat formatter = new DecimalFormat("#,###.00");
System.out.println(formatter.format(PV));
然后,调用实例“三”,并在显示时传递双精度值:
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
String s = String.format(%,.2f, PV);
System.out.println(s);