title: Java 8 sort float values
body: <p>I have a list of employees which had different experiences like</p>
  
  <blockquote>
    <p>5.0,3.3,5.5,5.6,4.5 etc..</p>
  </blockquote>
  
  <p>When I am trying to sort max to min experience by using <code>Math.round</code> it's giving the wrong result like:</p>
  
  <blockquote>
    <p>5.6,5.0,5.5,5.3,4.5 etc..</p>
  </blockquote>
  
  <p>I want the result like:</p>
  
  <blockquote>
    <p>5.6,5.5,5.3,5.0,4.5 etc..</p>
  </blockquote>
  
  <p>Here I used <code>Collections.sort</code> like:</p>
  
  <pre><code>Collections.sort(employeeList, new Comparator&lt;Emp&gt;() {
          @Override
          public int compare(Emp t, Emp t1) {
              return Math.round(t.getExperience() - t1.getExperience()); // which giving wrong results
  //          return Float.compare(t.getExperience() - t1.getExperience()); // which is not working
          }
      });
  </code></pre>
  
  <p>Here <code>t1.getExperience()</code> will give you float result.</p>