-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.3
-
Component/s: Serialization
-
Environment:x64
-
Fully Compatible
The following fix broke an important feature of rounding Double to a few digits.
Commit : d918bb829beafa619db061394ce183f00619b880
Issue : CSHARP-1731: Use "G17" instead of "R" when converting Double to Strin...
The standard C# Double.ToString() method serializes 15 digits instead of 17 and this is on purpose. It allows approximation to look like an exact number. For instance, 7.33 is stored as
7.3300000000000001. Using G17 instead of R prohibit using Math.Round to output a JSON document that contains "7.33".
Sample Code:
Double d1 = 7.33333333333;
Double d2 = Math.Round(d1, 2);
BsonValue v2 = d2;
String s2 = v2.ToString();
The main problem for me is when I consume the JSON document in JavaScript with Meteor on the website. I need again to round in JavaScript. Would that be possible to at least provide an option or another class like BsonDoubleR that would allow to control the desired behavior. That was working before I upgraded the driver for MongoDB 3.4 support.
- is related to
-
CSHARP-1858 Add user configurable output converters to JsonWriter
- Closed