title: java - remove float leftovers elegantly
body: <p>In brief - I am having a hard time with the float left overs<br>
   (i.e. 10.00000123 instead of 10)</p>
  
  <p>Here I go : </p>
  
  <p>I need to generate list of floats with constant gap as follows 
  (actually its a map , I need to retreive the object nut nevermind that)</p>
  
  <p>List A: 0.25, 0.5, 0.75, 1, ...<br>
  or<br>
  List B: 0.01, 0.02, 0.03, 0.04, ...  </p>
  
  <p>every time I get a number and I round it to the neerest cell in the list.<br>
  lets say I get 0.051 to retreive a cell in list A - I return 0.05.<br>
  lets say I get 0.21 to retreive a cell in list B - I return 0.25.  </p>
  
  <p>So I started be doing this     </p>
  
  <pre><code>float a = Math.round(Value / step) * step;
  </code></pre>
  
  <p>but than I get a lot of time 0.2500001  (float leftovers ) 
  I need a smart way to round it . </p>
  
  <p>Maybe by taking the number of digits after the dot and doing again   </p>
  
  <pre><code>Math.round(Value / 100) * 100;?
  </code></pre>
  
  <p>Is there a smarter way? 
  I tried doig this </p>
  
  <pre><code>        final float factor = Math.round(1 / step);
          final float value = (float) Math.round(value * factor) / factor;
  </code></pre>
  
  <p>but I sometimes have a list like this </p>
  
  <p>List A: 10, 15 , 20, 25, 30, ...</p>
  
  <p>and when I get 22 I retreive the cell of 20. 
  the problem is that When I get a gap of 10 </p>
  
  <pre><code>Math.round(1 / baseAssetStep) 
  </code></pre>
  
  <p>returns 0 - and I get NaN</p>