title: How can I fix this method that convert Number in String to show the correct number of decimal digits?
body: <p>I have the following problem.</p>
  
  <p>I am using this method to convert a Number (as a BigDecimal) to a formatted string:</p>
  
  <pre><code>/**
   * @param n il Number da formattare
   * @param thou_sep separator for hundreds
   * @param dec_sep  separator for decimal digits
   * @param number of decimal digits to show
   * @return a string representing the number
   * @author Andrea Nobili
   */
  public static String getFormattedNumber(Number n, String thou_sep, String dec_sep, Integer decimalDigits) {
  
      if (n == null) return "";
  
      double value = n.doubleValue();
  
      if (decimalDigits != null &amp;&amp; decimalDigits &lt; 0)
          throw new IllegalArgumentException("[" + decimalDigits + " &lt; 0]");
  
      DecimalFormatSymbols s = new DecimalFormatSymbols();
      if (thou_sep != null &amp;&amp; thou_sep.length() &gt; 0) {
          s.setGroupingSeparator(thou_sep.charAt(0));
      }
      if (dec_sep != null &amp;&amp; dec_sep.length() &gt; 0) {
          s.setDecimalSeparator(dec_sep.charAt(0));
      }
      DecimalFormat f = new DecimalFormat();
      f.setDecimalFormatSymbols(s);
      if (thou_sep == null || thou_sep.length() == 0) {
          f.setGroupingUsed(false);
      }
      if (decimalDigits != null) {
          f.setMaximumFractionDigits(decimalDigits);
      }
      f.setMaximumIntegerDigits(Integer.MAX_VALUE);
      String formattedNumber = f.format(value);
      return ("-0".equals(formattedNumber)) ? "0" : formattedNumber;
  }
  </code></pre>
  
  <p>For example if I call something like:</p>
  
  <pre><code>utilityClass.getFormattedNumber(57.4567, null, ",", 2)
  </code></pre>
  
  <p>I obtain the string <strong>57,45</strong></p>
  
  <p>Ok, this work fine.</p>
  
  <p>My problem is that if I try to perform it with a number having not decimal digits (for example passing the value <strong>57</strong> it return the String <strong>57</strong>. I want that in this case it return the string <strong>57.00</strong> (because I have specified that I want 2 decimal digits in the input parameter of this method)</p>
  
  <p>How can I fix this issue and obtain the correct number of decimal digits?</p>