title: Objective-C: Flooring to 3 decimals correctly
body: <p>I am trying to floor a float value to the third decimal. For example, the value 2.56976 shall be 2.569 not 2.570. I searched and found answers like these:</p>
  
  <p><a href="https://stackoverflow.com/questions/3273179/floor-double-by-decimal-place">floor double by decimal place</a></p>
  
  <p>Such answers are not accurate. For example the code:</p>
  
  <pre><code>double value = (double)((unsigned int)(value * (double)placed)) / (double)placed
  </code></pre>
  
  <p>can return the <code>value - 1</code> and this is not correct. The multiplication of value and placed <code>value * (double)placed)</code> could introduce something like: 2100.999999996. When changed to unsigned int, it becomes 2100 which is wrong (the correct value should be 2101). Other answers suffer from the same issue. In Java, you can use <code>BigDecimal</code> which saves all that hassels. </p>
  
  <p>(Note: of course, rounding the 2100.9999 is not an option as it ruins the whole idea of flooring to "3 decimals correctly")</p>