$floor (Floor)

Last updated: 2026-10-09

$floor (Floor)

$floor returns the largest integer less than or equal to a given number — rounding down. It is used to round amounts down, compute lower bounds, or bucket values, such as bucketing prices downward by 10-unit steps. A null or missing argument yields null and integers pass through unchanged. It is the opposite of $ceil: -1.2 becomes -2 with $floor but -1 with $ceil; it also differs from $trunc, which truncates toward zero so -1.2 becomes -1.

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $floor: <numeric-expression> }

⚙️ Parameters

numeric valueA numeric value or an expression resolving to one.

Returns:The largest integer less than or equal to the input; null when null or missing

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $floor: round prices down to whole yuan
db.products.aggregate([
  { $project: {
      priceFloor: { $floor: '$price' }
  } }
])

Output:

{ '_id': 1, 'priceFloor': 9 }
{ '_id': 2, 'priceFloor': 12 }

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QHow do $floor and $trunc differ on negatives?
A$floor rounds toward negative infinity (-1.2 becomes -2) while $trunc cuts toward zero (-1.2 becomes -1).
QWhat does $floor return for null?
AIt returns null without throwing.
QCan $floor keep decimal places?
ANo; use $round or $trunc to keep decimal places.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏