title: How to divide a float number and cast the result to integer in Android
body: <hr>
  
  <h2>Problem</h2>
  
  <p>Suppose <code>int childCount = linearLayout.getChildCount()</code> returns a number that is a multiple of three plus one, e.g. <code>4</code>, <code>7</code>, <code>10</code>, <code>13</code>....</p>
  
  <p>I want to add two to that <code>childCount</code> and divide it by three to get my desired result for the number of my list, e.g. <code>(7 + 2) / 3</code> should give an answer of <code>3</code>, but I don't whether it would be <code>2</code> or <code>4</code> just because the error when doing the float operation. So I do it like this to make sure I get <code>3</code> as the result:</p>
  
  <pre><code>int numberOfCells = (int) ((linearLayout.getChildCount() + 2) / 3 + 0.5f);
  </code></pre>
  
  <p>Is it correct?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>Because there are two sub view (lines) in my linear layout following each relative layout (also the child of linear layout). But the last relative layout has no lines following. So what I wanna get the number of relative layouts, that is also the number of cells of the list that I'm gonna make.</p>
  
  <hr>
  
  <h2>Update 2</h2>
  
  <p>Is that statement,</p>
  
  <pre><code>int numberOfCells = (int) ((linearLayout.getChildCount() + 2) / 3 + 0.5f);
  </code></pre>
  
  <p>equivalent to</p>
  
  <pre><code>int numberOfCells = (int) Math.floor((linearLayout.getChildCount() + 2) / 3 + 0.5f);
  </code></pre>