0

I'm reading and writing a file, but I need the output to be formatted to 2 decimal places? How do you do "writer.write" with a double and format it?

whitney
  • 1
  • 2
  • This question certainly IS on-topic if it's a duplicate. The most helpful solution is to vote for duplicate. – 4castle May 19 '16 at 21:53

1 Answers1

0
System.out.printf("%.02f", 0.1234); 

Output:

0.12

System.out.printf("%.02f", 0.1); 

Ouput:

 0.10

OR:

new DecimalFormat("#.##").format(1.199);

Results in:

1.2
Olian04
  • 5,841
  • 2
  • 29
  • 49