title: MongoDB - How to Truncate Float Values to One or Two decimal points in aggregate?
body: <p>Let's say this is the query:</p>
  <pre><code>db.movies.aggregate([
    {$match: {languages: &quot;English&quot;, cast:{$exists:true}}},
  
    {$unwind: &quot;$cast&quot;},
  
    {$group: {_id: &quot;$cast&quot;, numFilms:{$sum: 1}, average:{$avg: &quot;$imdb.rating&quot;}   
    }},
  
    {$sort: {numFilms:-1}},
  
    {$limit: 1}
  ])
  </code></pre>
  <p>And I get the output:</p>
  <pre><code>{ &quot;_id&quot; : &quot;John Wayne&quot;, &quot;numFilms&quot; : 107, &quot;average&quot; : 6.424299065420561 }
  </code></pre>
  <p>How can I truncate <code>average</code> to single/double decimal points? I wanted to see an output like this:</p>
  <pre><code>{ &quot;_id&quot; : &quot;John Wayne&quot;, &quot;numFilms&quot; : 107, &quot;average&quot; : 6.42 }
  </code></pre>
  <p>I tried this <a href="https://stackoverflow.com/questions/17482623/rounding-to-2-decimal-places-using-mongodb-aggregation-framework">post</a>, but seems like I can't get away doing the same with <code>$avg</code> operator. How can I achieve this?</p>
  <h2>Potential duplicate</h2>
  <p>I believe the above linked isn't a duplicate, because mine deals with <code>$avg</code> operator.</p>