title: How to correctly floor doubles in Java to two digits
body: <p>I'm trying to floor (not round!) doubles to two digits in a Java application. I use <code>DecimalFormat</code> for this, but noticed that for negative values close to zero, the values are not rounded to <code>-0.01</code> but to <code>-0.00</code>. </p>
  
  <pre><code>public class MyTest {
  
      void formatAndPrint(double value) {
          DecimalFormat df = new DecimalFormat("0.00");
          df.setRoundingMode(RoundingMode.FLOOR);
  
          System.out.println(value + " =&gt; " + df.format(value));
      }
  
      @Test
      public void testFloor() {
          formatAndPrint(2.3289);  //  2.32
          formatAndPrint(2.3);     //  2.30
          formatAndPrint(-1.172);  // -1.18
          formatAndPrint(0.001);   //  0.00
          formatAndPrint(0.0001);  //  0.00
          formatAndPrint(-0.001);  // -0.01
          formatAndPrint(-0.0001); // -0.00 WRONG, expected: -0.01
      }
  }
  </code></pre>
  
  <p>Other solutions like <code>Math.floor(value * 100.0) / 100.0</code> does not have this issue but has other issues, like wrongly flooring <code>2.3</code> to <code>2.29</code>.</p>
  
  <p>Is there a flooring solution for Java which works in all cases?</p>