How to display values only upto 2 decimal places double in java
<p>I am doing this Java question :</p>

<blockquote>
  <p>Jalaj purchased a table for Rs.200.4 and due to some scratches on its
  top he had to sell it for Rs.176.5. Find his loss and loss%.</p>
  
  <p>LOSS : Cost Price - Selling Price</p>
  
  <p>LOSS% : (LOSS/Cost Price)*100</p>
  
  <p>a. Declare four double variables i.e. costprice, sellingPrice, loss,
  lossPercentage</p>
  
  <p>b. Assign 200.4 to costPrice and 176.5 to sellingPrice.</p>
  
  <p>c. Print loss and lossPercentage according to the given formulas like:
  823.67 8.23 d.</p>
  
  <p>For printing upto two decimal places use</p>

<pre><code>System.out.printf("%.2f\n", loss);
</code></pre>
  
  <p>Note:</p>
  
  <ol>
  <li><p>output for both should be upto two decimal places</p></li>
  <li><p>Output should be displayed in two different lines</p></li>
  </ol>
</blockquote>

<p>My code:</p>

<pre><code>/*Write your code here */
import java.util.Scanner;
class bkws{
    public static void main(String args[]){
        double costPrice,sellingPrice,loss,lossPercentage;
        costPrice=200.4;
        sellingPrice=176.5;
        loss=costPrice-sellingPrice;
        lossPercentage=(loss/costPrice)*100;
        System.out.print("%.2f",loss);
        System.out.println("%.2f",lossPercentage);
    }
}
</code></pre>

<p>Now I am thinking of using <code>Math.round</code> but for rounding off to 2 decimal places it should be:</p>

<pre><code>Math.round(number*100)/100;
</code></pre>

<p>But it is giving error and I also want to know that if there is any easy way to round off to <code>n</code> decimal places without using <code>Math.round</code> in Java.</p>