title: Java - How to round up float (or BigDecimal ) value by 0.5?
body: <p>Seems simple question but <strong>I really suck at math</strong> and few examples online I've searched seems not working for me. (the result just return the same value as input etc)</p>
  
  <p>For instance.. but its in C not Java
  <a href="https://stackoverflow.com/questions/2302927/round-to-next-05-in-c">Round to Next .05 in C</a></p>
  
  <p>So my goal is I have <code>%.1f</code> format <code>float</code> or <code>double</code> or <code>big decimal</code> and wanting to <strong>round it up to nearest .5</strong></p>
  
  <pre><code>example:
  
  1.3 --&gt; 1.5
  5.5 --&gt; 5.5
  2.4 --&gt; 2.5
  3.6 --&gt; 4.0
  7.9 --&gt; 8.0
  </code></pre>
  
  <p>I tried following example but didn't work :( below just output 1.3 which is original value. I wanted it to be 1.5</p>
  
  <pre><code>public class tmp {
  
      public static void main(String[] args) {
  
        double foo = 1.3;
  
        double mid = 20 * foo;
  
        System.out.println("mid " + mid);
  
        double out = Math.ceil(mid);
  
        System.out.println("out after ceil " + out);
  
        System.out.printf("%.1f\n", out/20.0);
      }
  }
  </code></pre>