title: Trying to format double data types with system.out.printf in java
body: <p>I'm attempting to format a series of calculations into a table. So far I've gotten string data types to work, but double data types seem to behave differently. I get the format conversion errors when the program is run. I'm new to java, and any help would be greatly appreciated. I am trying to get it to look like this:</p>
  
  <pre><code>RATE    YEAR    AMOUNT ON DEPOSIT   INTEREST
  ----    ----    -----------------   --------
  0.07     1        1,070.00          70.00
           2        1,144.90          144.90
           3        1,225.04          225.04
           4        1,310.80          310.80
           5        1,402.55          402.55
           6        1,500.73          500.73
           7        1,605.78          605.78
           8        1,718.19          718.19
           9        1,838.46          838.46
           10       1,967.15          967.15
  </code></pre>
  
  <p>Here is my code: ( I know that the loop is off if it's going to look like the above. I'm just trying to figure out how to format doubles first.)</p>
  
  <pre><code>import java.text.DecimalFormat;
  public class interest
  {
      public static void main(String[] args)
      {
          DecimalFormat money = new DecimalFormat("$#,##0.00");
          DecimalFormat percent = new DecimalFormat("0.00");
          double interest = 0;
          double principal = 1000;
          double rate7 = 0.07;
          double rate8 = 0.08;
          double rate9 = 0.09;
          double rate10 = 0.10;
          double endYear = 0;
          int yearCount = 1;
          System.out.printf("%1s%7s%20s%10s", "Rate", "Year", "Amount on Deposit" , "Interest");
          System.out.println();
          System.out.printf("%1s%7s%20s%10s", "----", "----", "-----------------", "--------");
          System.out.println();
          boolean firstTime =true;
          while (yearCount &lt;= 10)
          {
              if(firstTime)
              {  //the issue is here
                  System.out.printf("1f%7d%20f%10f", "percent.format(rate7)", "yearCount","endYear", "interest");
                  firstTime = false;
              }
              else
              {
                  endYear = principal * Math.pow((1 + rate7),yearCount);
                  System.out.println(money.format(endYear));
                  yearCount++;
                  interest = endYear - 1000;
                  System.out.println();
              }
          }
          System.out.format("%1s%7s%20s%10s", "Rate", "Year", "Amount on Deposit" , "Interest");
          System.out.println();
          System.out.format("%1s%7s%20s%10s", "----", "----", "-----------------", "--------");
          System.out.println();
          yearCount = 1;
          endYear = 0;
          interest = 0;
          firstTime = true;
          while (yearCount &lt;= 10)
          {
              if(firstTime)
              {
                  System.out.println(percent.format(rate8));
                  firstTime = false;
              }
              else
              {
                  endYear = principal * Math.pow((1 + rate8),yearCount);
                  yearCount++;
                  interest = endYear - 1000;
                  System.out.println(money.format(endYear));
              }
          }
          System.out.format("%1s%7s%20s%10s", "Rate", "Year", "Amount on Deposit" , "Interest");
          System.out.println();
          System.out.format("%1s%7s%20s%10s", "----", "----", "-----------------", "--------");
          System.out.println();
          yearCount = 1;
          endYear = 0;
          interest = 0;
          firstTime = true;
          while (yearCount &lt;= 10)
          {
              if(firstTime)
              {
                  System.out.println(percent.format(rate9));
                  firstTime = false;
              }
              else
              {
                  endYear = principal * Math.pow((1 + rate9),yearCount);
                  yearCount++;
                  interest = endYear - 1000;
                  System.out.println(money.format(endYear));
                  System.out.println();
              }
          }
          System.out.format("%1s%7s%20s%10s", "Rate", "Year", "Amount on Deposit" , "Interest");
          System.out.println();
          System.out.format("%1s%7s%20s%10s", "----", "----", "-----------------", "--------");
          System.out.println();
          yearCount = 1;
          endYear = 0;
          interest = 0;
          firstTime = true;
          while (yearCount &lt;= 10)
          {
              if(firstTime)
              {
                  System.out.println(percent.format(rate10));
                  firstTime = false;
              }
              else
              {
                  endYear = principal * Math.pow((1 + rate10),yearCount);
                  yearCount++;
                  interest = endYear - 1000;
                  System.out.println(money.format(endYear));
                  System.out.println();
              }
  
          }
      }
  }
  </code></pre>