$abs/$ceil/$floor/$round/$trunc

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Arithmetic expressions

What it does

Provides absolute value and rounding/truncation.

Syntax

Example: {$round: [number, place?]}

Use case

Format calculated metrics.

Important notes

Use decimal/integer money representations where precision matters.

$abs/$ceil/$floor/$round/$trunc: practical example
{ $project: { rounded: { $round: ["$amount", 2] }, magnitude: { $abs: "$delta" } } }
💡 Explanation Provides absolute value and rounding/truncation. When to use it Format calculated metrics. Caution Use decimal/integer money representations where precision matters.
Key Takeaways
  • Provides absolute value and rounding/truncation.
  • Typical use: Format calculated metrics.