Beispiel #1
0
        public static void Create_FromInteger()
        {
            var value = (SqlNumber)45993;

            Assert.True(value.CanBeInt32);
            Assert.True(value.CanBeInt64);
            Assert.Equal(0, value.Scale);
            Assert.Equal(5, value.Precision);
            Assert.False(SqlNumber.IsNaN(value));
            Assert.False(SqlNumber.IsNegativeInfinity(value));
            Assert.False(SqlNumber.IsPositiveInfinity(value));
            Assert.Equal(1, value.Sign);
        }
Beispiel #2
0
        public static void Create_FromDouble()
        {
            var value = (SqlNumber)459935.9803d;

            Assert.False(value.CanBeInt32);
            Assert.False(value.CanBeInt64);
            Assert.Equal(10, value.Scale);
            Assert.Equal(16, value.Precision);
            Assert.False(SqlNumber.IsNaN(value));
            Assert.False(SqlNumber.IsNegativeInfinity(value));
            Assert.False(SqlNumber.IsPositiveInfinity(value));
            Assert.Equal(1, value.Sign);
        }
        private SqlNumber ToDecimal(SqlNumber number)
        {
            if (SqlNumber.IsNaN(number))
            {
                return(SqlNumber.NaN);
            }
            if (SqlNumber.IsNegativeInfinity(number))
            {
                return(SqlNumber.NegativeInfinity);
            }
            if (SqlNumber.IsPositiveInfinity(number))
            {
                return(SqlNumber.PositiveInfinity);
            }

            var thisDiff  = Precision - Scale;
            var otherDiff = number.Precision - Scale;

            if (thisDiff == otherDiff)
            {
                return(number);
            }

            var value = number.innerValue;

            if (thisDiff > otherDiff)
            {
                value = BigMath.Scale(value, Scale);
            }
            else
            {
                value = BigMath.Scale(value, Scale - thisDiff);
            }

            return(new SqlNumber(SqlNumber.NumericState.None, value));
        }