Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3835

Incorrect Decimal128.fromString() for number with more than 34 significant digits

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.1
    • Component/s: js-bson

      What problem are you facing?

      Incorrect Decimal128.fromString() for number with more than 34 significant digits.

      What driver and relevant dependency versions are you using?

      node.js native mongodb driver 4.2.1 with bson 4.6.0

      Steps to reproduce?

      Decimal128.fromString('-46254.999999999999999132718749999999999998843625').toString()

      // got the wrong number -57365.00000000000000024382985000000

       

      Decimal128.fromString('-46254.99999999999999913271874999999').toString()

      // got the correct number -46254.9999999999999991327187499999

       

      Note that bson 1.x doesn't have this bug.

      // in bson 1.x

      Decimal128.fromString('-46254.999999999999999132718749999999999998843625').toString()

      // got the correct rounded number -46254.99999999999999913271875000000

            Assignee:
            Unassigned Unassigned
            Reporter:
            tzhuan@gmail.com Tz-Huan Huang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: