title: DecimalFormat - keep all decimal numbers
body: <p>I'm using DecimalFormat to format doubles into a String.
  This String is then integrated into my presentation layer.</p>
  
  <ul>
  <li><strong>Problem</strong>: I want to keep ALL decimals. <em>Example: "12345678.123456789"</em></li>
  <li><strong>Question</strong>: What format should I use? </li>
  <li><em>Remark</em>: I use a different Locale to support multiple layouts.</li>
  </ul>
  
  <p><strong>Format:</strong> <em>#.##</em> -> This uses <strong>ALL</strong> numbers <strong>BEFORE</strong> the decimal, but <strong>ROUNDS</strong> the numbers <strong>AFTER</strong> the decimal.</p>
  
  <p>I could use <em>#.#########</em> for the big decimal, but what if the decimal is even longer?</p>
  
  <p>I found my small test program useful and want to share it with you.</p>
  
  <p><strong><em>Can you help me to show ALL decimals?</em></strong></p>
  
  <pre><code>package be.softwarelab.numbers;
  
  import java.text.DecimalFormat;
  import java.text.DecimalFormatSymbols;
  import java.util.Locale;
  
  public class DecimalNumbersTest {
  
      private static final double NUMBER = 123456789.123456789;
  
      public static void main(String[] args) {
  
          String format01 = "#.";
          String format02 = "#.#";
          String format03 = "#.##";
          String format04 = "#.###";
          String format05 = "#.####"; 
  
          System.out.println("====== NUMBER ===== USA =====================================");
          showResult(NUMBER, format01, Locale.US);
          showResult(NUMBER, format02, Locale.US);
          showResult(NUMBER, format03, Locale.US);
          showResult(NUMBER, format04, Locale.US);
          showResult(NUMBER, format05, Locale.US);
          System.out.println("====== NUMBER ===== France ==================================");
          showResult(NUMBER, format01, Locale.FRANCE);
          showResult(NUMBER, format02, Locale.FRANCE);
          showResult(NUMBER, format03, Locale.FRANCE);
          showResult(NUMBER, format04, Locale.FRANCE);
          showResult(NUMBER, format05, Locale.FRANCE);
          System.out.println("=============================================================");
      }
  
      public static void showResult(double number, String format, Locale locale) {
          // Using a Locale to see the differences between regions.
          DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(locale);
          DecimalFormat formatter = new DecimalFormat (format, otherSymbols);
  
          // Create the String result
          String output = formatter.format(number);
  
          // Format the output for a nice presentation.
          System.out.format("    %s %11s = %20s\n", locale, format, output);
      }
  }
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code>====== NUMBER ===== USA =====================================
  en_US          #. =           123456789.
  en_US         #.# =          123456789.1
  en_US        #.## =         123456789.12
  en_US       #.### =        123456789.123
  en_US      #.#### =       123456789.1235
  ====== NUMBER ===== France ==================================
  fr_FR          #. =           123456789,
  fr_FR         #.# =          123456789,1
  fr_FR        #.## =         123456789,12
  fr_FR       #.### =        123456789,123
  fr_FR      #.#### =       123456789,1235
  =============================================================
  </code></pre>
  
  <p><strong>Edit:</strong> One user mentioned a related question: <a href="https://stackoverflow.com/questions/703396/how-to-nicely-format-floating-numbers-to-string-without-unnecessary-decimal-0">How to nicely format floating numbers to String without unnecessary decimal 0?</a>
  This question does not solve my problems, since it focuses on limiting the size, but I need to keep it as long as possible.</p>