Skip to main content

floor

$floor

Rounds a numeric value down to the specified number of decimal places. Non-numeric values are passed through unchanged. Safe to use in normalize phase (non-throwing).

Parameters

  • precision (number, optional): Number of decimal places to preserve. Defaults to 0 (round to integer).

Input/Output Examples:

  • $floor: 3.73, 9.999, -2.3-3
  • {$floor: 2}: 3.141593.14, 99.99999.99, 5.15.1
  • {$floor: 1}: 3.763.7, 9.019.0

Example

// Truncate to integer (floor toward zero for positive numbers)
new Schema('number').transformer('$floor')
// 9.99 → 9

// Preserve 2 decimal places, discarding extra precision
new Schema('number').transformer({$floor: {precision: 2}})
// 3.14159 → 3.14

// Strip sub-cent precision from a price field
new Schema('object', {
price: new Schema('number').transformer({$floor: {precision: 2}}),
})