Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50541

Problem when the $trunc operator

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • v4.4, v4.2, v4.0
    • Query 2021-01-11, Query Execution 2021-05-03, Query Execution 2021-05-17, QE 2021-10-18, QE 2021-11-01, QE 2021-11-15, QE 2021-11-29, QE 2021-12-13, QE 2021-12-27

      I have a problem when I truncate a number that has the same decimals that have the  <place> value. the problem is that the value is round to down and give the wrong number. I have the following situation:
      a number: 4.56 in my DB and the following query: { $project: { newField: { $trunc: ["$number", 2] }} }
      the outcome of this query is 4.55 a wrong value, I was expecting to get the same number that I stored before. The documentation says the following:

      Because of that, I don't understand the reason for the error and also the documentation doesn't show an example when the <place> and the <number> has the same digits.

       

      Image reference:

      Data on the DB

      Output, after apply the query 

       

       

       

       

        1. image-2020-08-20-17-32-19-994.png
          image-2020-08-20-17-32-19-994.png
          14 kB
        2. image-2020-08-20-17-33-08-167.png
          image-2020-08-20-17-33-08-167.png
          14 kB
        3. image-2020-08-20-17-35-17-122.png
          image-2020-08-20-17-35-17-122.png
          8 kB
        4. image-2020-08-20-17-35-41-798.png
          image-2020-08-20-17-35-41-798.png
          8 kB
        5. image-2020-08-20-17-38-05-874.png
          image-2020-08-20-17-38-05-874.png
          29 kB
        6. image-2020-08-20-17-39-09-282.png
          image-2020-08-20-17-39-09-282.png
          27 kB

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            evercabarcasmallarino@gmail.com Ever N/A
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: