0

I can achieve the following using DecimalFormat("0000.00000000");, e.g.

0000.00000028
0001.23450000
1234.56000012
0314.15000000

But can I achieve the following?

   0.00000028
   1.23450000
1234.56000012
 314.15000000

I want to basically centre everything about the decimal point. I tried a few combinations but could not find a solution. On the other hand, I am aware of String.format.

  • 1
    While an FAQ, I haven't seen anyone explain why it can't be done natively. The answer is that `DecimalFormat` does not support space padding by design, and the RFE to add it has been closed with a clunky workaround instead: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4248151 A less clunky method is the `printf` style: `System.out.print(String.format("%14.8f\n", number));` where 8 is the number of digits after the decimal point and 13 is the total number of characters, including any leading spaces, the digits and the decimal point. – Heath Raftery Jun 13 '17 at 23:00
  • This is a perfect answer. Thanks. –  Jun 14 '17 at 06:17

0 Answers0