Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3416

Discrepanices between BsonDocument and json strings on double values

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.4
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      .net framework 4.7.2

      var document = new BsonDocument {

      { "double1", 0.5710711036366942 }

      ,
      { "double2", 1.1897551732621 } ,
      { "double3", 1.680586318655911 } };

      var jsonDoc = document.ToJson();
      Console.WriteLine(jsonDoc);

       

      This default extension methods ToJson will output:

      { "double1" : 0.57107110363669422, "double2" : 1.1897551732620999, "double3" : 1.6805863186559109 }

       

      while insert this bson document into MongoDB won't introduce the discrepancy, the ToJson method will change the valid double values.  

      1. Could this be resolved by customized IBsonSerializer or JsonWriterSettings?

      2. Is it more reasonable to keep the same value in default ToJson() ?

       

      Thanks for the time and efforts in advance.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jiaxson@microsoft.com Jiaxing Song
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: