title: Java - Is it possible to figure out the DecimalFormat of a string
body: <p>I am trying to figure out how to, given a decimal through a <code>String</code> calculate the number of significant digits so that I can do a calculation to the decimal and print the result with the same number of significant digits. Here's an SSCCE:</p>
  
  <pre><code>import java.text.DecimalFormat;
  import java.text.ParseException;
  
  public class Test {
  
      public static void main(String[] args) {
          try {
              DecimalFormat df = new DecimalFormat();
              String decimal1 = "54.60"; // Decimal is input as a string with a specific number of significant digits.
              double d = df.parse(decimal1).doubleValue();
              d = d * -1; // Multiply the decimal by -1 (this is why we parsed it, so we could do a calculatin).
              System.out.println(df.format(d)); // I need to print this with the same # of significant digits.
          } catch (ParseException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I know <code>DecimalFormat</code> is to 1) tell the program how you intend your decimal to be displayed (<code>format()</code>) and 2) to tell the program what format to expect a String-represented decimal to be in (<code>parse()</code>). But, is there a way to DEDUCE the <code>DecimalFormat</code> from a parsed string and then use that same <code>DecimalFormat</code> to output a number? </p>