Chapter 3, Lab 2 - Truncate to 1 digit

I’ve got my answer for the question, no problem. Before I submit my answer, I have 2 small issues:

  1. . I wanted to programmatically truncate the average to 1 digit.

It’s possible (probable?) that I missed an instruction in a previous lesson. I’m aware that there’s no $round operator and $trunc appears to only round to the nearest integer, but there are plenty of ways to handle it using one of the myriad approaches JS/MQL enable…

Just wanted to confirm we’re not rounding, just a straight truncation. So for example, if a theoretical average was 7.36, I’d want to use 7.3 and not round up to 7.4.

  1. If I pasted my terminal output into the Answer Form, there’d be a slight difference in whitespace…

I.e. “_id” : , rather than “_id”:

I figure it should be as exact as possible, so be strict w/ whitespace, etc, but just wanted ask b/c we’ve only got the 3 attempts.

Hi, regarding average I did it manually, and with result in console, I copy it, paste it, and then I just make sure that every space between brackets, quotations, etc, matched the given one as an example. Hope it helps!

Hi,

Whitespace should not be a problem, but I would try to match the example, just in case. I can confirm that we expect to truncate the average to one decimal. This can be done in MongoDB multiplying by 10, then truncating, and finally dividing by 10.

For example, if we got an average of 7.36 (as you posted initially), we would get 73.6 after multiplying by 10, then we would get 73 after truncation, and finally 7.3 if we divide by 10.

Hope it helps.

José Carlos