[CSHARP-4648] Standardize handling of decimal vs Decimal128 Created: 09/May/23  Updated: 28/Oct/23  Resolved: 10/May/23

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

Type: Bug Priority: Unknown
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-4636 System.Decimal serialization/deserial... Closed
duplicates CSHARP-4637 Error in deserializing Decimal stored... Closed
Related
related to CSHARP-4496 JsonReader fails with BsonInternalExc... Closed
related to CSHARP-4636 System.Decimal serialization/deserial... Closed
related to CSHARP-4637 Error in deserializing Decimal stored... Closed
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Go through the entire code base ensuring that decimal and Decimal128 are handled consistently.

These types are not equivalent. They have different ranges and precisions. We should never automatically convert between them due to the potential for data loss.



 Comments   
Comment by Githook User [ 18/May/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4648: Standardize handling of decimal vs Decimal128.
Branch: v2.19.x
https://github.com/mongodb/mongo-csharp-driver/commit/8c4466d445a9b186b9ca9c20d2119cc27dc783cf

Comment by Githook User [ 10/May/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4648: Standardize handling of decimal vs Decimal128.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/b0e694cf15d071dcc23976ad0255975be4c5107f

Comment by Robert Stam [ 09/May/23 ]

The various "decimal" related types will be round tripped by the ObjectSerializer as follows:

  • decimal => { _t : "System.Decimal", _v : "1.5" }

    => decimal

  • Decimal128 => NumberDecimal("1.5") => Decimal128
  • BsonDecimal128 => { _t : "MongoDB.Bson.BsonDecimal128, MongoDB.Bson", _v : NumberDecimal("1.5") }

    => BsonDecimal128

The following principles apply:

  • all three types round trip faithfully
  • no automatic conversions between decimal and Decimal128 (such conversions have the potential to fail)
Generated at Wed Feb 07 21:48:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.