[CSHARP-196] the 'System.Decimal' type save as 'String' Created: 07/Apr/11  Updated: 14/Dec/16  Resolved: 07/Apr/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.0
Fix Version/s: 1.0

Type: Bug Priority: Major - P3
Reporter: ymind chan Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

the 'System.Decimal' type save as 'String', but Want it to be 'Number'



 Comments   
Comment by Robert Stam [ 07/Apr/11 ]

A decimal value is serialized by default as a string because BSON has no decimal type. You can override this and choose to serialize a decimal as a BSON double like this:

public class C

{ public ObjectId Id; [BsonRepresentation(BsonType.Double)] public decimal X; }

WARNING: a BSON double does not have the same range as a decimal value, so when you do this you might get overflow exceptions or you might lose precision. When you store it as a string we can guarantee that there will never be any overflow or loss of precision.

Comment by Testo [ 07/Apr/11 ]

It's been discussed earlier why it has been implemented this way.
http://groups.google.com/group/mongodb-user/browse_thread/thread/277c485d78ba6e28/9afbe64067b81695?show_docid=9afbe64067b81695

Generated at Wed Feb 07 21:36:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.