I have a problem with values of type double. I’m trying to create a BsonValue with the value 47.11. I tried new BsonDouble() and BsonValue.Create(). In both options the driver (MongoDB.Driver 2.19.0) creates a BsonValue of type double, but with a wired value. Instead of 47.11 I get 47.109999999999999. The same happens, when I use document.ToJson() I also get the wrong value.
When I look at the document in Studio 3T the value is correct (47.11).
Welcome to the MongoDB forum. I understand that you’re having trouble with the precision of doubles in BSON. There’s a few ways to deal with this, but the simplest will be to store these values using the Decimal128 type. Here’s some useful articles for that:
Hi Darius-- this is more of a question about C# than MongoDB. You’ll need to let C# know that you want to use that decimal as a monetary value. You can do that by appending an ‘M’ to the value declaration, e.g.: