1

In mongo I have amount stored as 4.77 with type double.

enter image description here

I am using mongo's C# driver to read the Bson document

     var collection = _mongoDatabase.GetCollection<BsonDocument>("mycollection");
     var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
     await collection.Find(filter)
            .ForEachAsync(document => 
            {                    
                var val = document.GetValue("amount");
            });

However, it reads the value as 4.7699999999999996

enter image description here

LP13
  • 30,567
  • 53
  • 217
  • 400
  • That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed. – itsundefined Nov 12 '18 at 23:34

0 Answers0