-2
double PV = 154055.054847215

How can I display this as 1,540,055.055 ?

JNL
  • 4,683
  • 18
  • 29
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97

3 Answers3

4

add this instance of DecimalFormat to the top of your method:

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 "#"

then, call the instance "three" and pass your double value when displaying:

double PV = 154055.054847215;
display.setText(three.format(PV)); // displays 1,540,055.055
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
1

Try this:

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

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

Source

Community
  • 1
  • 1
gwin003
  • 7,432
  • 5
  • 38
  • 59
1
String s = String.format(%,.2f, PV);

System.out.println(s);