コード例 #1
0
        public void MathContextConstruction()
        {
            String       a         = "-12380945E+61";
            BigDecimal   aNumber   = BigDecimal.Parse(a);
            int          precision = 6;
            RoundingMode rm        = RoundingMode.HalfDown;
            MathContext  mcIntRm   = new MathContext(precision, rm);
            MathContext  mcStr     = MathContext.Parse("precision=6 roundingMode=HALFDOWN");
            MathContext  mcInt     = new MathContext(precision);
            BigDecimal   res       = BigMath.Abs(aNumber, mcInt);

            Assert.Equal(res, BigDecimal.Parse("1.23809E+68"));

            Assert.Equal(mcIntRm, mcStr);

            Assert.Equal(mcInt.Equals(mcStr), false);

            Assert.Equal(mcIntRm.GetHashCode(), mcStr.GetHashCode());

            Assert.Equal(mcIntRm.ToString(), "precision=6 roundingMode=HalfDown");
        }
コード例 #2
0
        public void MathContextConstruction()
        {
            String       a         = "-12380945E+61";
            BigDecimal   aNumber   = BigDecimal.Parse(a);
            int          precision = 6;
            RoundingMode rm        = RoundingMode.HalfDown;
            MathContext  mcIntRm   = new MathContext(precision, rm);
            MathContext  mcStr     = MathContext.Parse("precision=6 roundingMode=HALFDOWN");
            MathContext  mcInt     = new MathContext(precision);
            BigDecimal   res       = aNumber.Abs(mcInt);

            Assert.AreEqual(res, BigDecimal.Parse("1.23809E+68"), "MathContext Constructor with int precision failed");

            Assert.AreEqual(mcIntRm, mcStr, "Equal MathContexts are not Equal ");

            Assert.AreEqual(mcInt.Equals(mcStr), false, "Different MathContext are reported as Equal ");

            Assert.AreEqual(mcIntRm.GetHashCode(), mcStr.GetHashCode(), "Equal MathContexts have different hashcodes ");

            Assert.AreEqual(mcIntRm.ToString(), "precision=6 roundingMode=HalfDown",
                            "MathContext.ToString() returning incorrect value");
        }