-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Summary
When deserialising certain valid numbers to System.Decimal (e.g. 9.300000190734863 ) an exception of MongoDB.Bson.TruncationException is thrown
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
Assembly: MongoDB.Bson, Version=2.21.0.0, Culture=neutral, PublicKeyToken=null
How to Reproduce
Here's some sample code that should work just fine but does not:
public class MyDocumentType { public decimal Number {get;set;} } public static void Main() { var validDecimalString = "9.300000190734863"; var validDecimal = Decimal.Parse(validDecimalString); Console.WriteLine(validDecimalString + " --> " + validDecimal); Console.WriteLine(); var myValidDecimalJson = "{\"Number\": 9.300000190734863 }"; try { var obj = BsonSerializer.Deserialize<MyDocumentType>(myValidDecimalJson); Console.WriteLine(myValidDecimalJson + " --> " + obj.Number); } catch (Exception e) { Console.WriteLine(myValidDecimalJson + " ---> " + e.GetType().Name + ": " + e.Message); } //Sample output: // 9.300000190734863 --> 9.300000190734863 // // {"Number": 9.300000190734863 } ---> FormatException: An error occurred while deserializing the Number property of class VetDB.Tests.My.SampleDeserialisations+MyDocumentType: Truncation resulted in data loss.
Additional Background
Please provide any additional background information that may be helpful in diagnosing the bug.