title: Rounding to 2 decimal places using MongoDB aggregation framework
body: <p>I am using the mongodb aggregation framework and doing some calculations as shown below</p>
  <pre><code>db.RptAgg.aggregate( 
    {$group: {
      _id: {Region: &quot;$RegionTxt&quot;, Mth: &quot;$Month&quot;},           
      ActSls: {$sum:&quot;$ActSls&quot;},
      PlnSls: {$sum:&quot;$PlnSls&quot;}
    }},
    {$project: {
      ActSls: 1,
      PlnSls: 1,
      ActToPln: {$cond: [
        {$ne: [&quot;$PlnSls&quot;, 0]}, 
        {$multiply: [{$divide: ['$ActSls', '$PlnSls']}, 100]}, 
        0
      ]}
    }}
  ); 
  </code></pre>
  <p>I am trying to figure out what is the best and easiest way to round my results to 2 decimal places. Following is my result</p>
  <pre><code>{
    &quot;result&quot;: [{
      &quot;_id&quot;: {
        &quot;Region&quot;: &quot;East&quot;,
        &quot;Mth&quot;: 201301
      },
      &quot;ActSls&quot;: 72,
      &quot;PlnSls&quot;: 102,
      &quot;ActToPln&quot;: 70.58823529411765
    }],
    &quot;ok&quot;: 1
  }
  </code></pre>
  <p><strong>I want &quot;ActToPln&quot; to show 70.59</strong> instead of <strong>&quot;ActToPln&quot; : 70.58823529411765</strong>, in the results from aggegation framework itself. I want to avoid doing the rounding in my application</p>
  <p>Can you please help with the same.</p>
  <p>Following is the dataset i used.</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;51d67ef69557c507cb172572&quot;),
      &quot;RegionTxt&quot; : &quot;East&quot;,
      &quot;Month&quot; : 201301,
      &quot;Date&quot; : &quot;2013-01-01&quot;,
      &quot;ActSls&quot; : 31,
      &quot;PlnSls&quot; : 51
  }
  {
      &quot;_id&quot; : ObjectId(&quot;51d67ef69557c507cb172573&quot;),
      &quot;RegionTxt&quot; : &quot;East&quot;,
      &quot;Month&quot; : 201301,
      &quot;Date&quot; : &quot;2013-01-02&quot;,
      &quot;ActSls&quot; : 41,
      &quot;PlnSls&quot; : 51
  }
  </code></pre>
  <p>Thanks in advance.
  Nandu</p>