public void Signum()
        {
            BigDecimal sign = new BigDecimal(123E-104);

            Assert.True(sign.Sign == 1, "123E-104 is not positive in signum()");
            sign = BigDecimal.Parse("-1234.3959");
            Assert.True(sign.Sign == -1, "-1234.3959 is not negative in signum()");
            sign = new BigDecimal(000D);
            Assert.True(sign.Sign == 0, "000D is not zero in signum()");
        }
        public void Abs()
        {
            BigDecimal big    = BigDecimal.Parse("-1234");
            BigDecimal bigabs = BigMath.Abs(big);

            Assert.True(bigabs.ToString().Equals("1234"), "the absolute value of -1234 is not 1234");
            big    = new BigDecimal(BigInteger.Parse("2345"), 2);
            bigabs = BigMath.Abs(big);
            Assert.True(bigabs.ToString().Equals("23.45"), "the absolute value of 23.45 is not 23.45");
        }
        public void Negate()
        {
            BigDecimal negate1 = new BigDecimal(value2, 7);

            Assert.True((-negate1).ToString().Equals("-1233.4560000"), "the negate of 1233.4560000 is not -1233.4560000");
            negate1 = BigDecimal.Parse("-23465839");
            Assert.True((-negate1).ToString().Equals("23465839"), "the negate of -23465839 is not 23465839");
            negate1 = new BigDecimal(-3.456E6);
            Assert.True((-(-negate1)).Equals(negate1), "the negate of -3.456E6 is not 3.456E6");
        }
        public void ToInt64()
        {
            BigDecimal long1 = new BigDecimal(value2.Negate(), 0);

            Assert.IsTrue(long1.ToInt64() == -12334560000L, "the long value of 12334560000 is not 12334560000");
            long1 = new BigDecimal(-1345.348E-123D);
            Assert.IsTrue(long1.ToInt64() == 0, "the long value of -1345.348E-123D is not zero");
            long1 = BigDecimal.Parse("31323423423419083091823091283933");
            // ran JDK and found representation for the above was
            // -5251313250005125155
            Assert.IsTrue(long1.ToInt64() == -5251313250005125155L, "the long value of 31323423423419083091823091283933 is wrong");
        }
        public void ToInt32()
        {
            BigDecimal int1 = new BigDecimal(value, 3);

            Assert.IsTrue(int1.ToInt32() == 12345, "the int value of 12345.908 is not 12345");
            int1 = BigDecimal.Parse("1.99");
            Assert.IsTrue(int1.ToInt32() == 1, "the int value of 1.99 is not 1");
            int1 = BigDecimal.Parse("23423419083091823091283933");
            // ran JDK and found representation for the above was -249268259
            Assert.IsTrue(int1.ToInt32() == -249268259, "the int value of 23423419083091823091283933 is wrong");
            int1 = new BigDecimal(-1235D);
            Assert.IsTrue(int1.ToInt32() == -1235, "the int value of -1235 is not -1235");
        }
        public void TestToString()
        {
            BigDecimal toString1 = BigDecimal.Parse("1234.000");

            Assert.IsTrue(toString1.ToString().Equals("1234.000"), "the ToString representation of 1234.000 is wrong");
            toString1 = BigDecimal.Parse("-123.4E-5");
            Assert.IsTrue(toString1.ToString().Equals("-0.001234"),
                          "the ToString representation of -123.4E-5 is wrong: " + toString1);
            toString1 = BigDecimal.Parse("-1.455E-20");
            Assert.IsTrue(toString1.ToString().Equals("-1.455E-20"), "the ToString representation of -1.455E-20 is wrong");
            toString1 = new BigDecimal(value2, 4);
            Assert.IsTrue(toString1.ToString().Equals("1233456.0000"), "the ToString representation of 1233456.0000 is wrong");
        }
        public void UnscaledValue()
        {
            BigDecimal unsVal = BigDecimal.Parse("-2839485.000");

            Assert.IsTrue(unsVal.UnscaledValue.ToString().Equals("-2839485000"), "the unscaledValue of -2839485.000 is wrong");
            unsVal = new BigDecimal(123E10);
            Assert.IsTrue(unsVal.UnscaledValue.ToString().Equals("1230000000000"), "the unscaledValue of 123E10 is wrong");
            unsVal = BigDecimal.Parse("-4.56E-13");
            Assert.IsTrue(unsVal.UnscaledValue.ToString().Equals("-456"),
                          "the unscaledValue of -4.56E-13 is wrong: " + unsVal.UnscaledValue);
            unsVal = new BigDecimal(value, 3);
            Assert.IsTrue(unsVal.UnscaledValue.ToString().Equals("12345908"), "the unscaledValue of 12345.908 is wrong");
        }
        public void ParseString()
        {
            BigDecimal big = BigDecimal.Parse("345.23499600293850");

            Assert.IsTrue(big.ToString().Equals("345.23499600293850") && big.Scale == 14,
                          "the BigDecimal value is not initialized properly");
            big = BigDecimal.Parse("-12345");
            Assert.IsTrue(big.ToString().Equals("-12345") && big.Scale == 0, "the BigDecimal value is not initialized properly");
            big = BigDecimal.Parse("123.");
            Assert.IsTrue(big.ToString().Equals("123") && big.Scale == 0, "the BigDecimal value is not initialized properly");

            BigDecimal.Parse("1.234E02");
        }
        public void CompareToBigDecimal()
        {
            BigDecimal comp1 = BigDecimal.Parse("1.00");
            BigDecimal comp2 = new BigDecimal(1.000000D);

            Assert.IsTrue(comp1.CompareTo(comp2) == 0, "1.00 and 1.000000 should be equal");
            BigDecimal comp3 = BigDecimal.Parse("1.02");

            Assert.IsTrue(comp3.CompareTo(comp1) == 1, "1.02 should be bigger than 1.00");
            BigDecimal comp4 = new BigDecimal(0.98D);

            Assert.IsTrue(comp4.CompareTo(comp1) == -1, "0.98 should be less than 1.00");
        }
        public void AddBigDecimal()
        {
            BigDecimal add1 = BigDecimal.Parse("23.456");
            BigDecimal add2 = BigDecimal.Parse("3849.235");
            BigDecimal sum  = add1.Add(add2);

            Assert.IsTrue(sum.UnscaledValue.ToString().Equals("3872691") && sum.Scale == 3,
                          "the sum of 23.456 + 3849.235 is wrong");
            Assert.IsTrue(sum.ToString().Equals("3872.691"), "the sum of 23.456 + 3849.235 is not printed correctly");
            BigDecimal add3 = new BigDecimal(12.34E02D);

            Assert.IsTrue((add1.Add(add3)).ToString().Equals("1257.456"), "the sum of 23.456 + 12.34E02 is not printed correctly");
        }
        public void DivideBigDecimalII()
        {
            BigDecimal divd1 = new BigDecimal(value2, 4);
            BigDecimal divd2 = BigDecimal.Parse("0.0023");
            BigDecimal divd3 = divd1.Divide(divd2, 3, RoundingMode.HalfUp);

            Assert.IsTrue(divd3.ToString().Equals("536285217.391") && divd3.Scale == 3, "1233456/0.0023 is not correct");
            divd2 = new BigDecimal(1345.5E-02D);
            divd3 = divd1.Divide(divd2, 0, RoundingMode.Down);
            Assert.IsTrue(divd3.ToString().Equals("91672") && divd3.Scale == 0,
                          "1233456/13.455 is not correct or does not have the correct scale");
            divd2 = new BigDecimal(0000D);

            Assert.Throws <ArithmeticException>(() => divd1.Divide(divd2, 4, RoundingMode.Down));
        }
        public void DivideBigDecimalI()
        {
            BigDecimal divd1 = new BigDecimal(value, 2);
            BigDecimal divd2 = BigDecimal.Parse("2.335");
            BigDecimal divd3 = divd1.Divide(divd2, RoundingMode.Up);

            Assert.IsTrue(divd3.ToString().Equals("52873.27") && divd3.Scale == divd1.Scale, "123459.08/2.335 is not correct");
            Assert.IsTrue(divd3.UnscaledValue.ToString().Equals("5287327"),
                          "the unscaledValue representation of 123459.08/2.335 is not correct");
            divd2 = new BigDecimal(123.4D);
            divd3 = divd1.Divide(divd2, RoundingMode.Down);
            Assert.IsTrue(divd3.ToString().Equals("1000.47") && divd3.Scale == 2, "123459.08/123.4  is not correct");
            divd2 = new BigDecimal(000D);

            Assert.Throws <ArithmeticException>(() => divd1.Divide(divd2, RoundingMode.Down));
        }
        public void ToBigInteger()
        {
            BigDecimal sub1   = BigDecimal.Parse("-29830.989");
            BigInteger result = sub1.ToBigInteger();

            Assert.IsTrue(result.ToString().Equals("-29830"), "the bigInteger equivalent of -29830.989 is wrong");
            sub1   = new BigDecimal(-2837E10);
            result = sub1.ToBigInteger();
            Assert.IsTrue(result.ToDouble() == -2837E10, "the bigInteger equivalent of -2837E10 is wrong");
            sub1   = new BigDecimal(2.349E-10);
            result = sub1.ToBigInteger();
            Assert.IsTrue(result.Equals(BigInteger.Zero), "the bigInteger equivalent of 2.349E-10 is wrong");
            sub1   = new BigDecimal(value2, 6);
            result = sub1.ToBigInteger();
            Assert.IsTrue(result.ToString().Equals("12334"), "the bigInteger equivalent of 12334.560000 is wrong");
        }
        public void StripTrailingZero()
        {
            BigDecimal sixhundredtest = BigDecimal.Parse("600.0");

            Assert.IsTrue(((sixhundredtest.StripTrailingZeros()).Scale == -2), "stripTrailingZero failed for 600.0");

            /* Single digit, no trailing zero, odd number */
            BigDecimal notrailingzerotest = BigDecimal.Parse("1");

            Assert.IsTrue(((notrailingzerotest.StripTrailingZeros()).Scale == 0), "stripTrailingZero failed for 1");

            /* Zero */
            //regression for HARMONY-4623, NON-BUG DIFF with RI
            BigDecimal zerotest = BigDecimal.Parse("0.0000");

            Assert.IsTrue(((zerotest.StripTrailingZeros()).Scale == 0), "stripTrailingZero failed for 0.0000");
        }
        public void BigDecimalSerialization()
        {
            // Regression for HARMONY-1896
            char[]     input = { '1', '5', '6', '7', '8', '7', '.', '0', '0' };
            BigDecimal bd    = BigDecimal.Parse(input, 0, 9);

            MemoryStream    bos = new MemoryStream();
            BinaryFormatter oos = new BinaryFormatter();

            oos.Serialize(bos, bd);

            MemoryStream bis = new MemoryStream(bos.ToArray());
            BigDecimal   nbd = (BigDecimal)oos.Deserialize(bis);

            Assert.AreEqual(bd.ToInt32(), nbd.ToInt32());
            Assert.AreEqual(bd.ToDouble(), nbd.ToDouble(), 0.0);
            Assert.AreEqual(bd.ToString(), nbd.ToString());
        }
Esempio n. 16
0
        /**
         * Returns a new {@code BigDecimal} instance with the same value as {@code
         * this} but with a unscaled value where the trailing zeros have been
         * removed. If the unscaled value of {@code this} has n trailing zeros, then
         * the scale and the precision of the result has been reduced by n.
         *
         * @return a new {@code BigDecimal} instance equivalent to this where the
         *         trailing zeros of the unscaled value have been removed.
         */

        public static BigDecimal StripTrailingZeros(BigDecimal value)
        {
            int  i        = 1;     // 1 <= i <= 18
            int  lastPow  = BigDecimal.TenPow.Length - 1;
            long newScale = value.Scale;

            if (value.IsZero)
            {
                return(BigDecimal.Parse("0"));
            }
            BigInteger strippedBI = value.UnscaledValue;
            BigInteger quotient;
            BigInteger remainder;

            // while the number is even...
            while (!BigInteger.TestBit(strippedBI, 0))
            {
                // To divide by 10^i
                quotient = DivideAndRemainder(strippedBI, BigDecimal.TenPow[i], out remainder);
                // To look the remainder
                if (remainder.Sign == 0)
                {
                    // To adjust the scale
                    newScale -= i;
                    if (i < lastPow)
                    {
                        // To set to the next power
                        i++;
                    }
                    strippedBI = quotient;
                }
                else
                {
                    if (i == 1)
                    {
                        // 'this' has no more trailing zeros
                        break;
                    }
                    // To set to the smallest power of ten
                    i = 1;
                }
            }
            return(new BigDecimal(strippedBI, BigDecimal.ToIntScale(newScale)));
        }
        public void Scale()
        {
            BigDecimal scale1 = new BigDecimal(value2, 8);

            Assert.IsTrue(scale1.Scale == 8, "the scale of the number 123.34560000 is wrong");
            BigDecimal scale2 = BigDecimal.Parse("29389.");

            Assert.IsTrue(scale2.Scale == 0, "the scale of the number 29389. is wrong");
            BigDecimal scale3 = new BigDecimal(3.374E13);

            Assert.IsTrue(scale3.Scale == 0, "the scale of the number 3.374E13 is wrong");
            BigDecimal scale4 = BigDecimal.Parse("-3.45E-203");

            // note the scale is calculated as 15 digits of 345000.... + exponent -
            // 1. -1 for the 3
            Assert.IsTrue(scale4.Scale == 205, "the scale of the number -3.45E-203 is wrong: " + scale4.Scale);
            scale4 = BigDecimal.Parse("-345.4E-200");
            Assert.IsTrue(scale4.Scale == 201, "the scale of the number -345.4E-200 is wrong");
        }
        public void ToSingle()
        {
            BigDecimal fl1 = BigDecimal.Parse("234563782344567");

            Assert.IsTrue(fl1.ToSingle() == 234563782344567f, "the float representation of bigDecimal 234563782344567");
            BigDecimal fl2 = new BigDecimal(2.345E37);

            Assert.IsTrue(fl2.ToSingle() == 2.345E37F, "the float representation of bigDecimal 2.345E37");
            fl2 = new BigDecimal(-1.00E-44);
            Assert.IsTrue(fl2.ToSingle() == -1.00E-44F, "the float representation of bigDecimal -1.00E-44");
            fl2 = new BigDecimal(-3E12);
            Assert.IsTrue(fl2.ToSingle() == -3E12F, "the float representation of bigDecimal -3E12");
            fl2 = new BigDecimal(Double.MaxValue);
            Assert.IsTrue(fl2.ToSingle() == Single.PositiveInfinity,
                          "A number can't be represented by float should return infinity");
            fl2 = new BigDecimal(-Double.MaxValue);
            Assert.IsTrue(fl2.ToSingle() == Single.NegativeInfinity,
                          "A number can't be represented by float should return infinity");
        }
        public void EqualsObject()
        {
            BigDecimal equal1 = new BigDecimal(1.00D);
            BigDecimal equal2 = BigDecimal.Parse("1.0");

            Assert.IsFalse(equal1.Equals(equal2), "1.00 and 1.0 should not be equal");
            equal2 = new BigDecimal(1.01D);
            Assert.IsFalse(equal1.Equals(equal2), "1.00 and 1.01 should not be equal");
            equal2 = BigDecimal.Parse("1.00");
            Assert.IsFalse(equal1.Equals(equal2), "1.00D and 1.00 should not be equal");
            BigInteger val = BigInteger.Parse("100");

            equal1 = BigDecimal.Parse("1.00");
            equal2 = new BigDecimal(val, 2);
            Assert.IsTrue(equal1.Equals(equal2), "1.00(string) and 1.00(bigInteger) should be equal");
            equal1 = new BigDecimal(100D);
            equal2 = BigDecimal.Parse("2.34576");
            Assert.IsFalse(equal1.Equals(equal2), "100D and 2.34576 should not be equal");
            Assert.IsFalse(equal1.Equals("23415"), "bigDecimal 100D does not equal string 23415");
        }
        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");
        }
        public void MovePointRightI()
        {
            BigDecimal movePtRight  = BigDecimal.Parse("-1.58796521458");
            BigDecimal alreadyMoved = movePtRight.MovePointRight(8);

            Assert.IsTrue(alreadyMoved.Scale == 3 && alreadyMoved.ToString().Equals("-158796521.458"),
                          "move point right 8 failed");
            movePtRight  = new BigDecimal(value, 2);
            alreadyMoved = movePtRight.MovePointRight(4);
            Assert.IsTrue(alreadyMoved.Scale == 0 && alreadyMoved.ToString().Equals("1234590800"), "move point right 4 failed");
            movePtRight  = new BigDecimal(134E12);
            alreadyMoved = movePtRight.MovePointRight(2);
            Assert.IsTrue(alreadyMoved.Scale == 0 && alreadyMoved.ToString().Equals("13400000000000000"),
                          "move point right 2 failed");
            movePtRight  = new BigDecimal(-3.4E-10);
            alreadyMoved = movePtRight.MovePointRight(5);
            Assert.IsTrue(alreadyMoved.Scale == movePtRight.Scale - 5 && alreadyMoved.ToDouble() == -0.000034,
                          "move point right 5 failed");
            alreadyMoved = alreadyMoved.MovePointRight(-5);
            Assert.IsTrue(alreadyMoved.Equals(movePtRight), "move point right -5 failed");
        }
        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");
        }
        public void MovePointLeftI()
        {
            BigDecimal movePtLeft   = BigDecimal.Parse("123456265.34");
            BigDecimal alreadyMoved = movePtLeft.MovePointLeft(5);

            Assert.IsTrue(alreadyMoved.Scale == 7 && alreadyMoved.ToString().Equals("1234.5626534"), "move point left 5 failed");
            movePtLeft   = new BigDecimal(value2.Negate(), 0);
            alreadyMoved = movePtLeft.MovePointLeft(12);
            Assert.IsTrue(alreadyMoved.Scale == 12 && alreadyMoved.ToString().Equals("-0.012334560000"),
                          "move point left 12 failed");
            movePtLeft   = new BigDecimal(123E18);
            alreadyMoved = movePtLeft.MovePointLeft(2);
            Assert.IsTrue(alreadyMoved.Scale == movePtLeft.Scale + 2 && alreadyMoved.ToDouble() == 1.23E18,
                          "move point left 2 failed");
            movePtLeft   = new BigDecimal(1.123E-12);
            alreadyMoved = movePtLeft.MovePointLeft(3);
            Assert.IsTrue(alreadyMoved.Scale == movePtLeft.Scale + 3 && alreadyMoved.ToDouble() == 1.123E-15,
                          "move point left 3 failed");
            movePtLeft   = new BigDecimal(value, 2);
            alreadyMoved = movePtLeft.MovePointLeft(-2);
            Assert.IsTrue(alreadyMoved.Scale == movePtLeft.Scale - 2 && alreadyMoved.ToString().Equals("12345908"),
                          "move point left -2 failed");
        }
        public void TestGetHashCode()
        {
            // anything that is equal must have the same hashCode
            BigDecimal hash  = BigDecimal.Parse("1.00");
            BigDecimal hash2 = new BigDecimal(1.00D);

            Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2),
                          "the hashCode of 1.00 and 1.00D is equal");
            hash2 = BigDecimal.Parse("1.0");
            Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2),
                          "the hashCode of 1.0 and 1.00 is equal");
            BigInteger val = BigInteger.Parse("100");

            hash2 = new BigDecimal(val, 2);
            Assert.IsTrue(hash.GetHashCode() == hash2.GetHashCode() && hash.Equals(hash2),
                          "hashCode of 1.00 and 1.00(bigInteger) is not equal");
            hash  = new BigDecimal(value, 2);
            hash2 = BigDecimal.Parse("-1233456.0000");
            Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2),
                          "hashCode of 123459.08 and -1233456.0000 is not equal");
            hash2 = new BigDecimal(value.Negate(), 2);
            Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2),
                          "hashCode of 123459.08 and -123459.08 is not equal");
        }
        public void SubtractBigDecimal()
        {
            BigDecimal sub1   = BigDecimal.Parse("13948");
            BigDecimal sub2   = BigDecimal.Parse("2839.489");
            BigDecimal result = sub1.Subtract(sub2);

            Assert.IsTrue(result.ToString().Equals("11108.511") && result.Scale == 3, "13948 - 2839.489 is wrong: " + result);
            BigDecimal result2 = sub2.Subtract(sub1);

            Assert.IsTrue(result2.ToString().Equals("-11108.511") && result2.Scale == 3, "2839.489 - 13948 is wrong");
            Assert.IsTrue(result.Equals(result2.Negate()), "13948 - 2839.489 is not the negative of 2839.489 - 13948");
            sub1   = new BigDecimal(value, 1);
            sub2   = BigDecimal.Parse("0");
            result = sub1.Subtract(sub2);
            Assert.IsTrue(result.Equals(sub1), "1234590.8 - 0 is wrong");
            sub1   = new BigDecimal(1.234E-03);
            sub2   = new BigDecimal(3.423E-10);
            result = sub1.Subtract(sub2);
            Assert.IsTrue(result.ToDouble() == 0.0012339996577, "1.234E-03 - 3.423E-10 is wrong, " + result.ToDouble());
            sub1   = new BigDecimal(1234.0123);
            sub2   = new BigDecimal(1234.0123000);
            result = sub1.Subtract(sub2);
            Assert.IsTrue(result.ToDouble() == 0.0, "1234.0123 - 1234.0123000 is wrong, " + result.ToDouble());
        }
 public void ParseStringPlusMinusExp()
 {
     Assert.Throws <FormatException>(() => BigDecimal.Parse("+35e+-2"));
     Assert.Throws <FormatException>(() => BigDecimal.Parse("-35e-+2"));
 }
 public void ParseStringEmpty()
 {
     Assert.Throws <FormatException>(() => BigDecimal.Parse(""));
 }
 public void ParseCharArrayPlusMinusExp()
 {
     Assert.Throws <FormatException>(() => BigDecimal.Parse("+35e+-2".ToCharArray()));
     Assert.Throws <FormatException>(() => BigDecimal.Parse("-35e-+2".ToCharArray()));
 }
        public void SetScaleII()
        {
            BigDecimal setScale1 = new BigDecimal(2.323E102);
            BigDecimal setScale2 = setScale1.SetScale(4);

            Assert.IsTrue(setScale2.Scale == 4, "the number 2.323E102 after setting scale is wrong");
            Assert.IsTrue(setScale2.ToDouble() == 2.323E102, "the representation of the number 2.323E102 is wrong");
            setScale1 = BigDecimal.Parse("-1.253E-12");
            setScale2 = setScale1.SetScale(17, RoundingMode.Ceiling);
            Assert.IsTrue(setScale2.Scale == 17, "the number -1.253E-12 after setting scale is wrong");
            Assert.IsTrue(setScale2.ToString().Equals("-1.25300E-12"),
                          "the representation of the number -1.253E-12 after setting scale is wrong, " + setScale2);

            // testing rounding Mode ROUND_CEILING
            setScale1 = new BigDecimal(value, 4);
            setScale2 = setScale1.SetScale(1, RoundingMode.Ceiling);
            Assert.IsTrue(setScale2.ToString().Equals("1234.6") && setScale2.Scale == 1,
                          "the number 1234.5908 after setting scale to 1/ROUND_CEILING is wrong");
            BigDecimal setNeg = new BigDecimal(value.Negate(), 4);

            setScale2 = setNeg.SetScale(1, RoundingMode.Ceiling);
            Assert.IsTrue(setScale2.ToString().Equals("-1234.5") && setScale2.Scale == 1,
                          "the number -1234.5908 after setting scale to 1/ROUND_CEILING is wrong");

            // testing rounding Mode ROUND_DOWN
            setScale2 = setNeg.SetScale(1, RoundingMode.Down);
            Assert.IsTrue(setScale2.ToString().Equals("-1234.5") && setScale2.Scale == 1,
                          "the number -1234.5908 after setting scale to 1/ROUND_DOWN is wrong");
            setScale1 = new BigDecimal(value, 4);
            setScale2 = setScale1.SetScale(1, RoundingMode.Down);
            Assert.IsTrue(setScale2.ToString().Equals("1234.5") && setScale2.Scale == 1,
                          "the number 1234.5908 after setting scale to 1/ROUND_DOWN is wrong");

            // testing rounding Mode ROUND_FLOOR
            setScale2 = setScale1.SetScale(1, RoundingMode.Floor);
            Assert.IsTrue(setScale2.ToString().Equals("1234.5") && setScale2.Scale == 1,
                          "the number 1234.5908 after setting scale to 1/ROUND_FLOOR is wrong");
            setScale2 = setNeg.SetScale(1, RoundingMode.Floor);
            Assert.IsTrue(setScale2.ToString().Equals("-1234.6") && setScale2.Scale == 1,
                          "the number -1234.5908 after setting scale to 1/ROUND_FLOOR is wrong");

            // testing rounding Mode ROUND_HALF_DOWN
            setScale2 = setScale1.SetScale(3, RoundingMode.HalfDown);
            Assert.IsTrue(setScale2.ToString().Equals("1234.591") && setScale2.Scale == 3,
                          "the number 1234.5908 after setting scale to 3/ROUND_HALF_DOWN is wrong");
            setScale1 = new BigDecimal(BigInteger.Parse("12345000"), 5);
            setScale2 = setScale1.SetScale(1, RoundingMode.HalfDown);
            Assert.IsTrue(setScale2.ToString().Equals("123.4") && setScale2.Scale == 1,
                          "the number 123.45908 after setting scale to 1/ROUND_HALF_DOWN is wrong");
            setScale2 = BigDecimal.Parse("-1234.5000").SetScale(0, RoundingMode.HalfDown);
            Assert.IsTrue(setScale2.ToString().Equals("-1234") && setScale2.Scale == 0,
                          "the number -1234.5908 after setting scale to 0/ROUND_HALF_DOWN is wrong");

            // testing rounding Mode ROUND_HALF_EVEN
            setScale1 = new BigDecimal(1.2345789D);
            setScale2 = setScale1.SetScale(4, RoundingMode.HalfEven);
            Assert.IsTrue(setScale2.ToDouble() == 1.2346D && setScale2.Scale == 4,
                          "the number 1.2345789 after setting scale to 4/ROUND_HALF_EVEN is wrong");
            setNeg    = new BigDecimal(-1.2335789D);
            setScale2 = setNeg.SetScale(2, RoundingMode.HalfEven);
            Assert.IsTrue(setScale2.ToDouble() == -1.23D && setScale2.Scale == 2,
                          "the number -1.2335789 after setting scale to 2/ROUND_HALF_EVEN is wrong");
            setScale2 = BigDecimal.Parse("1.2345000").SetScale(3,
                                                               RoundingMode.HalfEven);
            Assert.IsTrue(setScale2.ToDouble() == 1.234D && setScale2.Scale == 3,
                          "the number 1.2345789 after setting scale to 3/ROUND_HALF_EVEN is wrong");
            setScale2 = BigDecimal.Parse("-1.2345000").SetScale(3,
                                                                RoundingMode.HalfEven);
            Assert.IsTrue(setScale2.ToDouble() == -1.234D && setScale2.Scale == 3,
                          "the number -1.2335789 after setting scale to 3/ROUND_HALF_EVEN is wrong");

            // testing rounding Mode ROUND_HALF_UP
            setScale1 = BigDecimal.Parse("134567.34650");
            setScale2 = setScale1.SetScale(3, RoundingMode.HalfUp);
            Assert.IsTrue(setScale2.ToString().Equals("134567.347") && setScale2.Scale == 3,
                          "the number 134567.34658 after setting scale to 3/ROUND_HALF_UP is wrong");
            setNeg    = BigDecimal.Parse("-1234.4567");
            setScale2 = setNeg.SetScale(0, RoundingMode.HalfUp);
            Assert.IsTrue(setScale2.ToString().Equals("-1234") && setScale2.Scale == 0,
                          "the number -1234.4567 after setting scale to 0/ROUND_HALF_UP is wrong");

            Assert.Throws <ArithmeticException>(() => setScale1.SetScale(3, RoundingMode.Unnecessary));

            // testing rounding Mode ROUND_UP
            setScale1 = BigDecimal.Parse("100000.374");
            setScale2 = setScale1.SetScale(2, RoundingMode.Up);
            Assert.IsTrue(setScale2.ToString().Equals("100000.38") && setScale2.Scale == 2,
                          "the number 100000.374 after setting scale to 2/ROUND_UP is wrong");
            setNeg    = new BigDecimal(-134.34589D);
            setScale2 = setNeg.SetScale(2, RoundingMode.Up);
            Assert.IsTrue(setScale2.ToDouble() == -134.35D && setScale2.Scale == 2,
                          "the number -134.34589 after setting scale to 2/ROUND_UP is wrong");

            Assert.Throws <ArgumentException>(() => setScale1.SetScale(0, -123));
        }