Floating-point precision issue when using $inc with Number type

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: 4.4.29
    • Component/s: None
    • ALL
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I am using MongoDB v4.4.
      In my Inventory collection, I have a field OnhandQty with Number type.

      The current value in the document is:
      OnhandQty = 9138.8

      When I run the update query:
      db.Inventory.updateOne(
        { _id: ... },
        { $inc:

      { OnhandQty: -4984.8 }

      }
      );

      Expected result:
      OnhandQty = 4154

      Actual result:
      OnhandQty = 4153.9999999999

      Issue:
      The result shows a floating-point precision error instead of the exact expected value. This is critical in use cases such as inventory and financial data where exact decimal precision is required.

      Additional notes:

      • Field type: Number (double precision)
      • MongoDB server version: 4.4

              Assignee:
              Kenan Ali
              Reporter:
              mayank padaliya
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: