Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试在 mongodb 中进行一些整数数学运算,但遇到了一些问题。有没有办法在 mongo db 聚合框架中向上或向下舍入双精度数?
根据 Stennie 的评论,不支持地板和天花板方法。
根据我上面的评论,我能找到的最好的解决方案就是做一个看起来像: (num-mod(num,1)) 的操作,它应该产生与 floor 函数相同的结果。
从MongoDB 3.2开始,您可以使用以下可用的算术聚合运算符:
ceil
trunc
floor
允许从您想要的任何一侧转换为整数。语法很简单:{ $function: <number> }
{ $function: <number> }