MongoDB.Bson.Serialization.Options.RepresentationSerializationOptions.ToDouble C# (CSharp) Метод

ToDouble() публичный Метод

Converts a Decimal to a Double.
public ToDouble ( decimal value ) : double
value decimal A Decimal.
Результат double
        public double ToDouble(decimal value)
        {
            if (value == decimal.MinValue)
            {
                return double.MinValue;
            }
            else if (value == decimal.MaxValue)
            {
                return double.MaxValue;
            }

            var doubleValue = (double)value;
            if (value != (decimal)doubleValue)
            {
                if (!_allowTruncation) { throw new TruncationException(); }
            }
            return doubleValue;
        }

Same methods

RepresentationSerializationOptions::ToDouble ( double value ) : double
RepresentationSerializationOptions::ToDouble ( float value ) : double
RepresentationSerializationOptions::ToDouble ( int value ) : double
RepresentationSerializationOptions::ToDouble ( long value ) : double
RepresentationSerializationOptions::ToDouble ( short value ) : double
RepresentationSerializationOptions::ToDouble ( uint value ) : double
RepresentationSerializationOptions::ToDouble ( ulong value ) : double
RepresentationSerializationOptions::ToDouble ( ushort value ) : double

Usage Example

 public void TestAllowTruncationTrue()
 {
     var options = new RepresentationSerializationOptions(BsonType.Int32, false, true);
     Assert.AreEqual((double)long.MaxValue, options.ToDouble(long.MaxValue));
     Assert.AreEqual((double)ulong.MaxValue, options.ToDouble(ulong.MaxValue));
     Assert.AreEqual((short)1, options.ToInt16((double)1.5));
     Assert.AreEqual((int)1, options.ToInt32((double)1.5));
     Assert.AreEqual((int)1, options.ToInt32((float)1.5F));
     Assert.AreEqual((long)1, options.ToInt64((double)1.5));
     Assert.AreEqual((long)1, options.ToInt64((float)1.5F));
     Assert.AreEqual((float)0.0F, options.ToSingle(double.Epsilon));
     Assert.AreEqual((ushort)1, options.ToUInt16((double)1.5));
     Assert.AreEqual((uint)1, options.ToUInt32((double)1.5));
     Assert.AreEqual((ulong)1, options.ToUInt64((double)1.5));
 }
All Usage Examples Of MongoDB.Bson.Serialization.Options.RepresentationSerializationOptions::ToDouble