Lab - $unwind - 2 Decimals

<deleted>

I try to take only 2 decimals, but I get an error and I do not know how to solve it.

<edited>
“avg”: {$divide:
[ { $trunc: { $avg: { $multiply: ["$imdb.rating", 100] } } },
100 ] } } },

@ Patricia_62551

Please follow Forum guidelines in the future and do not post code here. Thanks.

Here’s one way to truncate a result to 1 decimal place

$divide: [{ $trunc: { multiply: ["", 10] } }, 10]

Notice that the Lab question is looking for a 1 decimal answer as shown, not 2

{ "_id": "First Last", "numFilms": 1, "average": 1.1 }

Good luck.

2 Likes

“errmsg” : “$multiply only supports numeric types, not string”,

Hello @Memosha_53183,
just try to replace the empty space in the “multiple” expression to the rating field:wink:

@Memosha_53183

Ummm… yes. That wasn’t intended and is not simply something to cut-and-paste. You need to read and understand the formula, then apply it. Try again. Good luck.

Its working fine now. Just added logic to use multiply correctly

@Memosha_53183

Glad you got it working. Good luck.