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

Large integer-like doubles generate an incorrect string

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • bson-5.0.0, bson-4.7.2
    • Affects Version/s: bson-4.7.1, bson-5.0.0
    • Component/s: None
    • 2
    • Not Needed
    • Not Needed

      What problem are you facing?

      Large doubles that stringify with an exponential component will be suffixed with a trailing ".0". This will successfully roundtrip in JavaScript, because parseFloat begins ignoring a string once it encounters an invalid character. Other languages like Java will throw an exception for the incorrect formatting.

      const d = new BSON.Double(Number.MAX_VALUE);
      d.toExtendedJSON()
      // { '$numberDouble': '1.7976931348623157e+308.0' }
      

      What driver and relevant dependency versions are you using?

      Introduced in BSON v4.7.1

      Steps to reproduce?

      Launch jshell

      jshell> Double.valueOf("1.7976931348623157e+308.0")
      |  Exception java.lang.NumberFormatException: For input string: "1.7976931348623157e+308.0"
      |        at FloatingDecimal.readJavaFormatString (FloatingDecimal.java:2054)
      |        at FloatingDecimal.parseDouble (FloatingDecimal.java:110)
      

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: