當前位置: 首頁>>代碼示例>>C#>>正文


C# BigDecimal類代碼示例

本文整理匯總了C#中BigDecimal的典型用法代碼示例。如果您正苦於以下問題:C# BigDecimal類的具體用法?C# BigDecimal怎麽用?C# BigDecimal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BigDecimal類屬於命名空間,在下文中一共展示了BigDecimal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Move

 public override void Move(int moveX, int moveY)
 {
     TerminateThreads();
     xorigin -= (BigDecimal)(moveX) * (xmax - xmin) / (BigDecimal)screenWidth;
     yorigin -= (BigDecimal)(moveY) * (ymax - ymin) / (BigDecimal)screenHeight;
     Draw(numIterations, numThreads);
 }
開發者ID:dbrant,項目名稱:MandelbrotCsharp,代碼行數:7,代碼來源:SimpleBigIntRenderer.cs

示例2: TestBigDecimal

 public void TestBigDecimal() {
    BigDecimal decimal = new BigDecimal("1.1");
    BigDecimalTransform format = new BigDecimalTransform();
    String value = format.write(decimal);
    BigDecimal copy = format.read(value);
    AssertEquals(decimal, copy);
 }
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:7,代碼來源:BigDecimalTransformTest.cs

示例3: PayPalItem

		public PayPalItem (string name, BigDecimal price, string currency)
		{
			Name = name;
			//Quantity = quantity;
			Price = price;
			Currency = currency;
			//SKU = sku;
		}
開發者ID:15mgm15,項目名稱:PayPal.Forms,代碼行數:8,代碼來源:PayPalItem.cs

示例4: Add

 public void Add(string a, int aScale, string b, int bScale, string c, int cScale)
 {
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     BigDecimal result = aNumber.Add(bNumber);
     Assert.AreEqual(c, result.ToString(), "incorrect value");
     Assert.AreEqual(cScale, result.Scale, "incorrect scale");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:8,代碼來源:BigDecimalArithmeticTest.cs

示例5: Calculate

 public virtual Number Calculate(BigDecimal num)
 {
     if (num == null)
     {
         return -0;
     }
     return num.Negate();
 }
開發者ID:tupunco,項目名稱:Tup.Cobar4Net,代碼行數:8,代碼來源:MinusExpression.cs

示例6: EBig

        /// <summary>
        /// The mathematical constant e.
        /// </summary>
        /// <param name="precision">The precision.</param>
        /// <returns>The mathematical constant e.</returns>
        public static BigDecimal EBig(int precision)
        {
            if (_EBig.Precision < precision)
            {
                _EBig = BigDecimal.Exp(BigDecimal.One.WithPrecision(precision + 10));
            }

            return _EBig.WithPrecision(precision);
        }
開發者ID:jamiees2,項目名稱:Pie,代碼行數:14,代碼來源:Constants.cs

示例7: AddWithContext

 public void AddWithContext(string a, int aScale, string b, int bScale, string c, int cScale, int precision, RoundingMode mode)
 {
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     MathContext mc = new MathContext(precision, mode);
     BigDecimal result = aNumber.Add(bNumber, mc);
     Assert.AreEqual(c, result.ToString(), "incorrect value");
     Assert.AreEqual(cScale, result.Scale, "incorrect scale");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:9,代碼來源:BigDecimalArithmeticTest.cs

示例8: Abs

 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");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:9,代碼來源:BigDecimalTest.cs

示例9: CompareToBigDecimal

 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");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:10,代碼來源:BigDecimalTest.cs

示例10: AddBigDecimal

 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");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:11,代碼來源:BigDecimalTest.cs

示例11: Should_Allow_Custom_Primitive_Serializers

 public void Should_Allow_Custom_Primitive_Serializers()
 {
     var serializer = new Serializer(4, new [] {new BigDecimalSerializer()});
     var value = new BigDecimal(5, 1);
     var buffer = serializer.Serialize(value);
     CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 5, 1 }, buffer);
     var deserializedValue = serializer.Deserialize(buffer, ColumnTypeCode.Decimal, null);
     Assert.IsInstanceOf<BigDecimal>(deserializedValue);
     var deserializedDecimal = (BigDecimal) deserializedValue;
     Assert.AreEqual("0.00001", deserializedDecimal.ToString());
     Assert.AreEqual(value.Scale, deserializedDecimal.Scale);
     Assert.AreEqual(value.UnscaledValue, deserializedDecimal.UnscaledValue);
     //Check that other serializers are still working
     CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10));
     CollectionAssert.AreEqual(new byte[] { 0x61 }, serializer.Serialize("a"));
 }
開發者ID:alprema,項目名稱:csharp-driver,代碼行數:16,代碼來源:CustomTypeSerializerTests.cs

示例12: Zoom

        public override void Zoom(int posX, int posY, double factor)
        {
            BigDecimal xpos = xmin + ((BigDecimal)posX * (xmax - xmin) / (BigDecimal)screenWidth);
            BigDecimal ypos = ymin + ((BigDecimal)posY * (ymax - ymin) / (BigDecimal)screenHeight);
            BigDecimal xOffsetRatio = (xpos - xmin) / (xmax - xmin);
            BigDecimal yOffsetRatio = (ypos - ymin) / (ymax - ymin);

            BigDecimal newXextent = (xmax - xmin);
            newXextent *= factor;

            BigDecimal newYextent = (ymax - ymin);
            newYextent *= factor;

            TerminateThreads();
            xextent = newXextent;
            xorigin = xpos - xextent * xOffsetRatio;
            yorigin = ypos - newYextent * yOffsetRatio;
            Draw(numIterations, numThreads);
        }
開發者ID:dbrant,項目名稱:MandelbrotCsharp,代碼行數:19,代碼來源:SimpleBigIntRenderer.cs

示例13: DivideAndRemainder1

 public void DivideAndRemainder1()
 {
     String a = "3736186567876876578956958765675671119238118911893939591735";
     int aScale = 45;
     String b = "134432345432345748766876876723342238476237823787879183470";
     int bScale = 70;
     String res = "277923185514690367474770683";
     int resScale = 0;
     String rem = "1.3032693871288309587558885943391070087960319452465789990E-15";
     int remScale = 70;
     BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
     BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
     BigDecimal remainder;
     BigDecimal quotient = aNumber.DivideAndRemainder(bNumber, out remainder);
     Assert.AreEqual(res, quotient.ToString(), "incorrect quotient value");
     Assert.AreEqual(resScale, quotient.Scale, "incorrect quotient scale");
     Assert.AreEqual(rem, remainder.ToString(), "incorrect remainder value");
     Assert.AreEqual(remScale, remainder.Scale, "incorrect remainder scale");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:19,代碼來源:BigDecimalArithmeticTest.cs

示例14: ConstructorDouble

 public void ConstructorDouble()
 {
     BigDecimal big = new BigDecimal(123E04);
     Assert.AreEqual("1230000", big.ToString(),
                     "the BigDecimal value taking a double argument is not initialized properly");
     big = new BigDecimal(1.2345E-12);
     Assert.AreEqual(1.2345E-12, big.ToDouble(), "the double representation is not correct");
     big = new BigDecimal(-12345E-3);
     Assert.AreEqual(-12.345, big.ToDouble(), "the double representation is not correct");
     big = new BigDecimal(5.1234567897654321e138);
     Assert.AreEqual(5.1234567897654321E138, big.ToDouble(), "the double representation is not correct");
     Assert.AreEqual(0, big.Scale, "the double representation is not correct");
     big = new BigDecimal(0.1);
     Assert.IsTrue(big.ToDouble() == 0.1, "the double representation of 0.1 bigDecimal is not correct");
     big = new BigDecimal(0.00345);
     Assert.IsTrue(big.ToDouble() == 0.00345, "the double representation of 0.00345 bigDecimal is not correct");
     // regression test for HARMONY-2429
     big = new BigDecimal(-0.0);
     Assert.IsTrue(big.Scale == 0, "the double representation of -0.0 bigDecimal is not correct");
 }
開發者ID:tupunco,項目名稱:deveel-math,代碼行數:20,代碼來源:BigDecimalTest.cs

示例15: TestToString

		public void TestToString() {
			BigDecimal d;

			// integers
			d = new BigDecimal(0, 0);
			Assert.AreEqual("0.", d.ToString());

			d = new BigDecimal(1, 0);
			Assert.AreEqual("1.", d.ToString());

			// with decimal point inside number
			d = new BigDecimal(1234, 2);
			Assert.AreEqual("12.34", d.ToString());

			// with decimal point before number
			d = new BigDecimal(1, 2);
			Assert.AreEqual("0.01", d.ToString());

			// really big number, with decimal point
			d = new BigDecimal(BigInteger.Parse("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), 20);
			Assert.AreEqual("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.12345678901234567890", d.ToString());
		}
開發者ID:GameMoney,項目名稱:dotnet-big-decimal,代碼行數:22,代碼來源:TestDecimal.cs


注:本文中的BigDecimal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。