Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2001

Decimal128.ToDecimal should not throw an exception when the conversion can succeed with a loss of precision

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.5
    • 2.4.4
    • BSON
    • None
    • Win10

    Description

      The following causes an overflow error:

      var strValue = "10000.0000000000000000000000001";
      Decimal128 decimal128Value;
      Decimal128.TryParse( strValue, out decimal128Value );
      var decimalValue = Decimal128.ToDecimal( decimal128Value );
      

      Not that converting to double does not overflow:

      var doubleValue = Decimal128.ToDouble( decimal128Value );
      

      It is unclear why the Decimal128 value offers different precision than a standard .NET decimal. However the conversion to the .NET decimal should allow for a truncation of precision if necessary, as there currently is no other safe way to convert to decimal without going through some other type first (string or double).

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            ral628 Ryan Lawrence
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: