title: Java DecimalFormat with only negative exponents
body: <p>I am unable to define <code>DecimalFormat</code> instance (in Java1.8) with the following properties:</p>
  
  <ul>
  <li>Scientific notation (exponent) is used only if the exponent is negative.</li>
  <li>At most 4 significant places are shown, i.e., no 0s at the end.</li>
  </ul>
  
  <p>(I can live without the second property being satisfied if necessary.)</p>
  
  <p>The purpose is to convert doubles to strings, i.e., to use the <code>format</code> method. Here is the desired behaviour on some examples:</p>
  
  <pre><code>Representation of 9: 9
  Representation of 9.0: 9
  Representation of 9876.6: 9877
  Representation of 0.0098766: 9.877E-3
  Representation of 0.0000000098766: 9.877E-9
  </code></pre>
  
  <p>If I define <code>DecimalFormat df = new DecimalFormat("#.###E0");</code>, this gives</p>
  
  <pre><code>Representation of 9: 9E0
  Representation of 9.0: 9E0
  Representation of 9876.6: 9.877E3
  Representation of 0.0098766: 9.877E-3
  Representation of 0.0000000098766: 9.877E-9
  </code></pre>
  
  <p>which is wrong in the first three cases. Things like <code>DecimalFormat("#.###E#")</code> or <code>DecimalFormat("#.###E")</code> are not allowed (<code>IllegalArgumentException</code> is thrown).</p>
  
  <hr>
  
  <p>The code that produced the output is given below.</p>
  
  <pre><code>DecimalFormat df = new DecimalFormat("#.###E0");
  double[] xs = new double[] {9, 9.0, 9876.6, 0.0098766, 0.0000000098766};
  String[] xsStr = new String[] {"9", "9.0", "9876.6", "0.0098766", "0.0000000098766"};
  for(int i = 0; i &lt; xs.length; i++) {
      System.out.println("Representation of " + xsStr[i] + ": " + df.format(xs[i]));
  }
  </code></pre>