title: Java Double Round off to 2 decimal always
body: <p>I am trying to round off the double values to 2 decimal digits, however it's not working in all scenarios</p>
  
  <pre><code>public static double round(double value, int places) {
      if (places &lt; 0) throw new IllegalArgumentException();
  
      BigDecimal bd = new BigDecimal(value);
      bd = bd.setScale(places, RoundingMode.HALF_UP);
      return bd.doubleValue();
  }
  
  public static void main(String[] args) {
      System.out.println(round(25.0,2));  //25.0 - expected 25.00
      System.out.println(round(25.00d,2)); //25.0 - expected 25.00
      System.out.println(round(25,2));   //25.0 - expected 25.00
      System.out.println(round(25.666,2));  //25.67
  }
  </code></pre>
  
  <p>In short, no matter whether decimal exists or not, always hold the values upto 2 decimal even if it needs to pad additional zeros.</p>
  
  <p>Any help is appreciated!</p>