-2

How to ask Java to get a 20.30 output with a double without getting 20.3 but 20.30?

i tried with a 20.30d like a long but it didn't work.

Youss
  • 9
  • 1

1 Answers1

0

You can use the DecimalFormat class

DecimalFormat decimalFormat = new DecimalFormat("0.00");
    
double dub = 1.4142534543;
    
System.out.println("double format example : " + decimalFormat.format(dub));

alternatively you can use printf

double dub = 1.4142534543;
System.out.printf("%.2f", dub);
TedEllis
  • 66
  • 6