public void Abs() { BigDecimal big = BigDecimal.Parse("-1234"); BigDecimal bigabs = big.Abs(); Assert.IsTrue(bigabs.ToString().Equals("1234"), "the absolute value of -1234 is not 1234"); big = new BigDecimal(BigInteger.Parse("2345"), 2); bigabs = big.Abs(); Assert.IsTrue(bigabs.ToString().Equals("23.45"), "the absolute value of 23.45 is not 23.45"); }
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"); }