$round
Rounds a number to the nearest integer or to a specified decimal place.
Syntax
{ "$round": [ <numberExpression>, <placeExpression?> ] }
- Omit the second argument to round to the nearest integer.
- Supply a positive
placeto round to decimal places, or a negative value to round to tens, hundreds, etc.
Example
Input
{ "score": 87.456 }
Stage
{ "$project": { "scoreRounded": { "$round": ["$score", 1] } } }
Output
{ "scoreRounded": 87.5 }