[英]Mongodb how to round a calculated value
So i tried using $round on a calculated value but i still cant get it to work.所以我尝试在计算值上使用 $round ,但我仍然无法让它工作。 The current value now is: 9.333333333333334, but i would like to have: 9.3.
现在的当前值为:9.333333333333334,但我想要:9.3。
This is what i tried:这是我尝试过的:
{ $set: { power: { $sum: ["$power", "$attack", "$defence", { $divide: ["$endurance", 3] }, { $round: ["$power", -1] }] } } } ];
But this won't round the output, how do i fix this?但这不会围绕 output,我该如何解决?
$round has this syntax: $round有这样的语法:
{ $round : [ <number>, <place> ] }
<number>
can be any valid expression that resolves to a number. <number>
可以是任何解析为数字的有效表达式。<place>
is optional and can be any valid expression that resolves to an integer between -20 and 100. <place>
是可选的,可以是解析为介于 -20 和 100 之间的 integer 的任何有效表达式。 You code should look like:您的代码应如下所示:
{ $round : [ "$power", 1 ] }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.