title: Rounding Numbers with bc in Bash
body: <p>I want to compute an average with 3 decimal figures, rounded to nearest, using <code>bc</code>.</p>
  
  <p>For example:</p>
  
  <blockquote>
    <p>average of 3, 3 and 5 should yield 3.667</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>average of 3, 3 and 4 should yield 3.333</p>
  </blockquote>
  
  <p>I tried:</p>
  
  <pre><code>echo "scale=3; $sum/$n+0.0005" | bc
  </code></pre>
  
  <p>but <code>scale</code> doesn't behave as I expect. What can I do to solve my problem?</p>