I have this class
class MyClass
{
public Object? data { get; set; }
}
myClass.data = “Some String”;
BsonDocument bsonDocument = myClass.ToBsonDocument();
Console.WriteLine($“String:{bsonDocument.ToString()}”);
myClass.data = 45;
bsonDocument = myClass.ToBsonDocument();
Console.WriteLine($"int:{bsonDocument.ToString()}");
myClass.data = 0.345d;
bsonDocument = myClass.ToBsonDocument();
Console.WriteLine($"double:{bsonDocument.ToString()}");
myClass.data = 0.345f;
bsonDocument = myClass.ToBsonDocument();
Console.WriteLine($"float:{bsonDocument.ToString()}");
myClass.data = 0.345m;
bsonDocument = myClass.ToBsonDocument();
Console.WriteLine($"Decimal:{bsonDocument.ToString()}");
This gives this output, String,int, double work as expected, float and decimal not (.net 8.0 Mongdb driver 3.0.0):
String:{ “data” : “Some String” }
int:{ “data” : 45 }
double:{ “data” : 0.34499999999999997 }
float:{ “data” : { “_t” : “System.Single”, “_v” : 0.3449999988079071 } }
Decimal:{ “data” : { “_t” : “System.Decimal”, “_v” : “0.345” } }