title: How can I specify the number of decimal places with NumberFormat in Java?
body: <p>Let's run this code :</p>
  <pre><code>double number = 12345.678888;
  String str1 = String.format(Locale.FRANCE, &quot;%.10f&quot;, number);
  String str2 = NumberFormat.getInstance(Locale.FRANCE).format(number);
  
  System.out.println(str1);
  System.out.println(str2);
  </code></pre>
  <p>The outputs will be:</p>
  <blockquote>
  <p>12345,6788880000</p>
  <p>12 345,679</p>
  </blockquote>
  <p>But those aren't what I want. I want to specify the number of decimal places with <code>NumberFormat</code> just like <code>String.format()</code> can do. I also tried <code>DecimalFormat</code> as well but I don't think that's the answer.</p>
  <p>If I was writing C# code, it could be done simply like this :</p>
  <pre><code>string str = string.Format(new CultureInfo(&quot;fr-FR&quot;), &quot;{0:#,##0.0000000000}&quot;, number);
  </code></pre>
  <p>And the output would be:</p>
  <blockquote>
  <p>12 345,6788880000</p>
  </blockquote>
  <p>How can I achieve the same thing in Java?</p>