Exemple #1
0
        public BigDecimal(decimal dec)
        {
            Span <byte> dBytes = stackalloc byte[sizeof(decimal)];
            var         maxId  = DecimalHelper.CopyDecimalBigEndian(dBytes, dec);

            this.Scale = dBytes[2];

            var bi = BigInteger.Zero;

            for (var idx = 4; idx <= maxId; idx++)
            {
                bi <<= 8;
                bi  += dBytes[idx];
            }

            var negative = (dBytes[3] & 0x80) > 0;

            this.IntVal         = negative ? BigInteger.Negate(bi) : bi;
            this.IsNegativeZero = negative && this.IntVal == 0;
        }