title: How to always round off upto 2 decimal places in java
body: <p>I have tried the following code but it is not working in a <strong>particular case.</strong></p>
  
  <p>Eg: Suppose, I have a <strong>double value=2.5045</strong> and i want it to be rounded off upto <strong>two</strong> decimal places using the below code.After rounding off, i get the answer as <strong>2.5.</strong> But I want the answer to be <strong>2.50 instead.</strong> In this case,zero is trimmed off. Is there any way to retain the zero so as to get the desired answer as <strong>2.50</strong> after rounding off.</p>
  
  <pre><code> private static DecimalFormat twoDForm = new DecimalFormat("#.##");
           public static double roundTwoDecimals(double amount) {
                  return Double.valueOf(twoDForm.format(amount));
              }
  </code></pre>