Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4819

Allow reducing precision when converting BSON double values to JSON

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • C Drivers

      In _bson_as_json_visit_double, BSON double values are converted to strings with a precision of 20 decimal digits. This can lead to issue for some values when they are rounded at the default double precision (~16 digits) but not at the extended precision. An example for such a value is 1.99, which translates to 1.9899999999999999911 when 20 digits precision are available.

      This is problematic, as users using a value like above are presented with a different value in the resulting JSON. I'll note that reading the resulting JSON into BSON results in the original value, as the 20 digit precision is not available in a C double.

      A possible solution is changing the precision to a lower value: the 53 bits of precision in a double result in 16 digits of decimal precision. If this can be considered a BC break, adding a precision option to _bson_json_opts_t for use in bson_as_json_with_opts could provide a workaround for affected users.

            Assignee:
            Unassigned Unassigned
            Reporter:
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: