Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以特定格式显示数字(Android Eclipse,Java)_Java_Android_Eclipse - Fatal编程技术网

如何以特定格式显示数字(Android Eclipse,Java)

如何以特定格式显示数字(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("#

如何将其显示为1540055.055?

尝试以下操作:

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);