Skip to content

$trunc

Truncates a number toward zero to a specified precision (defaults to whole numbers).

Syntax

{ "$trunc": [ <numberExpression>, <placeExpression?> ] }
  • Omit place to drop everything after the decimal.
  • Use a positive place to keep decimal digits, or a negative place to truncate to tens, hundreds, etc.

Example

Input

{ "exchangeRate": 74.987 }

Stage

{ "$project": { "roundedDown": { "$trunc": ["$exchangeRate", 2] } } }

Output

{ "roundedDown": 74.98 }