当前位置: 首页>>代码示例>>C#>>正文


C# BigDecimal.ToString方法代码示例

本文整理汇总了C#中BigDecimal.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BigDecimal.ToString方法的具体用法?C# BigDecimal.ToString怎么用?C# BigDecimal.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigDecimal的用法示例。


在下文中一共展示了BigDecimal.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: Inspect

 public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, BigDecimal/*!*/ self) {
     MutableString str = MutableString.CreateMutable();
     str.AppendFormat("#<{0}:", context.GetClassOf(self).Name);
     RubyUtils.AppendFormatHexObjectId(str, RubyUtils.GetObjectId(context, self));
     str.AppendFormat(",'{0}',", self.ToString(10));
     str.AppendFormat("{0}({1})>", self.PrecisionDigits.ToString(), self.MaxPrecisionDigits.ToString());
     return str;
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:8,代码来源:BigDecimalOps.cs

示例4: ToString

        public static MutableString/*!*/ ToString(BigDecimal/*!*/ self, [DefaultProtocol][NotNull]MutableString/*!*/ format) {
            string posSign = "";
            int separateAt = 0;

            Match m = Regex.Match(format.ConvertToString(), @"^(?<posSign>[+ ])?(?<separateAt>\d+)?(?<floatFormat>[fF])?", RegexOptions.ExplicitCapture);
            Group posSignGroup = m.Groups["posSign"];
            Group separateAtGroup = m.Groups["separateAt"];
            Group floatFormatGroup = m.Groups["floatFormat"];

            if (posSignGroup.Success) {
                posSign = m.Groups["posSign"].Value;
            }
            if (separateAtGroup.Success) {
                separateAt = Int32.Parse(m.Groups["separateAt"].Value);
            }
            bool floatFormat = floatFormatGroup.Success;
            return MutableString.Create(self.ToString(separateAt, posSign, floatFormat));
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:18,代码来源:BigDecimalOps.cs

示例5: Dump

 public static MutableString/*!*/ Dump(BigDecimal/*!*/ self, [Optional]object limit) {
     // We ignore the limit value as BigDecimal does not contain other objects.
     return MutableString.CreateMutable(RubyEncoding.Binary).
         Append(self.MaxPrecisionDigits.ToString(CultureInfo.InvariantCulture)).
         Append(':').
         Append(self.ToString()
     );
 }
开发者ID:atczyc,项目名称:ironruby,代码行数:8,代码来源:BigDecimalOps.cs

示例6: NumberPolish

        public static string NumberPolish(string Number)
        {
            //首先要判别输入的数字是否为科学计数法
            int Char_E = Number.IndexOf('E');
            if (Char_E != -1)
            {
                //如果是科学计数法则先转化为常规格式
                Number = (new BigNumber(Number.Substring(0, Char_E - 1))
                    * MathV.Pow(10,Number.Substring(Char_E + 1,
                        Number.Length - Char_E-1))).ToString();
            }
            //目标为控制位数在10位
            Number = Number.Trim();
            int CountDecimalPoint = 0;
            int ScientificNumber;
            string ScientificNotation = "";
            int digits_part;
            BigDecimal NumberProcess = 0;
            string ProcessedNumber;
            char[] separator = { '.' };
            //用于分割小数点
            string[] NumberParts = new string[2];
            int IsNegative = 0;
            //用来判定数字是否为负
            int zero_count = 0;
            //用于计算小数点后有多少个零
            NumberParts = Number.Split(separator);
            if (NumberParts[0].Length + 5 > 10)
            //四位小数加上1个小数点
            {
                if (Number[0] == '-')
                {
                    IsNegative = 1;
                }
                foreach (char FindDecimalPoint in Number)
                {
                    if (FindDecimalPoint == '.')
                    {
                        CountDecimalPoint = 1;
                        break;
                    }
                }
                if (CountDecimalPoint == 0)
                {
                    //无小数点则只有整数部分
                    ScientificNumber = Number.Length - IsNegative - 1;
                    //转换为科学计数法
                    if (ScientificNumber <= 9 && ScientificNumber > 0)
                    {
                        ScientificNotation = "0" + ScientificNumber.ToString();
                        //如果科学计数法为个位要补零
                    }
                    else
                    {
                        ScientificNotation = ScientificNumber.ToString();
                    }
                    //数字正负无需考虑
                    if (ScientificNotation.Length + 1 + 2 <= 9)
                    {

                        //例如:-3.1415E+05
                        //数字负号占一位,E和科学计数法的符号占两位
                        //大于9的情况不做考虑,数字太大。
                        digits_part = 9 - (ScientificNotation.Length + 1 + 2);
                        //小数位由此算出
                        NumberProcess = new BigDecimal(Number.ToString()) / Math.Pow(10, ScientificNumber);
                        ProcessedNumber = MathV.round(NumberProcess.ToString(), digits_part, 0) + "E+" + ScientificNotation;
                    }
                    else
                    {
                        //如果已经大于已经大于九位了,则不作处理
                        //这种情况极为罕见,不考虑
                        NumberProcess = new BigDecimal(Number.ToString()) / Math.Pow(10, ScientificNumber);
                        ProcessedNumber = MathV.round(NumberProcess.ToString(), 0, 0) + "E+" + ScientificNotation;
                    }

                }
                else
                {
                    //有小数点的情况
                    NumberParts = Number.Split(separator);
                    if (NumberParts[0] != "0")
                    {
                        if (NumberParts[0].Length + 1 + 4 >= 9)
                        {
                            //如果保留四位小数之后依旧总长度超过九,则进行如下操作
                            //判断整数部分是否为0
                            //如果不为0,继续科学计数法的处理,舍去小数部分
                            ScientificNumber = NumberParts[0].Length - IsNegative - 1;
                            //转换为科学计数法
                            if (ScientificNumber <= 9 && ScientificNumber > 0)
                            {
                                ScientificNotation = "0" + ScientificNumber.ToString();
                                //如果科学计数法为个位要补零
                            }
                            else
                            {
                                ScientificNotation = ScientificNumber.ToString();
                            }
                            //数字正负无需考虑
//.........这里部分代码省略.........
开发者ID:JoshuaHe2015,项目名称:VISAP2.0_GUI,代码行数:101,代码来源:MathV.cs

示例7: ConstructorBigIntegerScale

 public void ConstructorBigIntegerScale()
 {
     BigDecimal big = new BigDecimal(value2, 5);
     Assert.IsTrue(big.UnscaledValue.Equals(value2) && big.Scale == 5, "the BigDecimal value is not initialized properly");
     Assert.IsTrue(big.ToString().Equals("123345.60000"), "the BigDecimal value is not represented properly");
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:6,代码来源:BigDecimalTest.cs

示例8: TestToString

 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");
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:12,代码来源:BigDecimalTest.cs


注:本文中的BigDecimal.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。