title: Trying to round to two decimal places in java
body: <p>The System.printf("%.2f", currentBalance) is working fine but the problem is the rounded number appears after the sentence. Put the code into your eclipse program and run it and you can see something is definitely wrong. If someone could help it would be much appreciated.</p>
  
  <pre><code>public class BankCompound {
  
  
  public static void main (String[] args) {
      compound (0.5, 1500, 1);
  }
  
  public static double compound (double interestRate, double currentBalance, int year) {
  
      for (; year &lt;= 9 ; year ++) {
  
      System.out.println ("At year " + year +  ", your total amount of money is ");
      System.out.printf("%.2f", currentBalance);
      currentBalance = currentBalance + (currentBalance * interestRate);  
      }
      System.out.println ("Your final balance after 10 years is " + currentBalance);
      return currentBalance;
  } 
  </code></pre>
  
  <p>}</p>