MongoDB.Bson.Serialization.Options.RepresentationSerializationOptions.ToDecimal C# (CSharp) Method

ToDecimal() public method

Converts a Double to a Decimal.
public ToDecimal ( double value ) : decimal
value double A Double.
return decimal
        public decimal ToDecimal(double value)
        {
            if (value == double.MinValue)
            {
                return decimal.MinValue;
            }
            else if (value == double.MaxValue)
            {
                return decimal.MaxValue;
            }

            var decimalValue = (decimal)value;
			if (decimalValue < decimal.MinValue || decimalValue > decimal.MaxValue)
            {
                if (!_allowOverflow) { throw new OverflowException(); }
            }
            else if (value != (double)decimalValue)
            {
                if (!_allowTruncation) { throw new TruncationException(); }
            }
            return decimalValue;
        }

Same methods

RepresentationSerializationOptions::ToDecimal ( int value ) : decimal
RepresentationSerializationOptions::ToDecimal ( long value ) : decimal