title: How do I format my percent variable to 2 decimal places?
body: <p>This program is basically working with text files, reading the data &amp; performing functions:</p>
  
  <pre><code>while(s.hasNext()){
      name= s.next();
  
      mark= s.nextDouble();
  
      double percent= (mark / tm )*100  ;
  
      System.out.println("Student Name      : " +name );
  
      System.out.println("Percentage In Exam: " +percent+"%"); 
  
      System.out.println(" ");
  }
  </code></pre>
  
  <p>I would like to format the percent value to 2 decimal places but since it's inside a while loop I cannot use the printf.</p>