Skip to main content

$trunc

The $trunc operator truncates the first number to the specified number of decimal places (rounds towards zero).

Input

  • An array containing exactly two numeric values: the number to truncate and the number of decimal places

Output

  • The first value truncated to the specified number of decimal places

Examples

Truncate to Integer

{
  "$trunc": [
    3.7,
    0
  ]
}
Result: 3

Truncate to One Decimal Place

{
  "$trunc": [
    3.14159,
    2
  ]
}
Result: 3.14

Truncate Negative Number

{
  "$trunc": [
    -3.7,
    0
  ]
}
Result: -3

Field Value

{
  "$trunc": [
    {
      "$input": "value"
    },
    1
  ]
}
Result: The value field truncated to 1 decimal place