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.7→3,9.99→9,-2.3→-3{$floor: 2}:3.14159→3.14,99.999→99.99,5.1→5.1{$floor: 1}:3.76→3.7,9.01→9.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}}),
})