[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. |