title: How do I round a double to two decimal places in Java?
body: <p>This is what I did to round a double to 2 decimal places:</p>
  
  <pre><code>amount = roundTwoDecimals(amount);
  
  public double roundTwoDecimals(double d) {
      DecimalFormat twoDForm = new DecimalFormat("#.##");
      return Double.valueOf(twoDForm.format(d));
  }
  </code></pre>
  
  <p>This works great if the amount = 25.3569 or something like that, but if the amount = 25.00 or the amount = 25.0, then I get 25.0!  What I want is both rounding as well as formatting to 2 decimal places. </p>