title: String.format() rounding a double with leading zeros in digits - Java
body: <p>I've asked this question already here in the comments:</p>
  <p><a href="https://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java">How to round a number to n decimal places in Java</a>.</p>
  <p>I'm trying to convert a double into a string with a fixed number of decimal places. In the question above the solution is quite simple.
  When using</p>
  <pre><code>String.format(&quot;%.4g&quot;, 0.1234712)
  </code></pre>
  <p>I get the expected result, a number rounded to 4 digits:</p>
  <pre><code>0.1235
  </code></pre>
  <p>But when there are zeros after the decimal dot:</p>
  <pre><code>String.format(&quot;%.4g&quot;, 0.000987654321)
  </code></pre>
  <p>This will return:</p>
  <pre><code>0,0009877
  </code></pre>
  <p>It looks like the function is ignoring the leading zeros in the digits.</p>
  <p>I know that I could just define a new DecimalFormat but I want to understand this issue. And learn a bit about the syntax.</p>