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


C# StringBuilder.AppendNumber方法代码示例

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


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

示例1: AppendIntTest

        public void AppendIntTest()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
              StringBuilder stringBuilder = new StringBuilder();

              stringBuilder.AppendNumber(1234567890);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(-1234567890);
              Assert.AreEqual("-1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.None);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign);
              Assert.AreEqual("+1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.NumberGroup);
              Assert.AreEqual("1,234,567,890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign | AppendNumberOptions.NumberGroup);
              Assert.AreEqual("+1,234,567,890", stringBuilder.ToString());
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:28,代码来源:StringBuilderHelperTest.cs

示例2: AppendFloatTest

        public void AppendFloatTest()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
              StringBuilder stringBuilder = new StringBuilder();

              stringBuilder.Clear();
              stringBuilder.AppendNumber(float.NaN);
              Assert.AreEqual("NaN", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(float.PositiveInfinity);
              Assert.AreEqual("+Infinity", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(float.NegativeInfinity);
              Assert.AreEqual("-Infinity", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234.12645f);
              Assert.AreEqual("1234.13", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1.23456f, 4, AppendNumberOptions.NumberGroup);
              Assert.AreEqual("1.2346", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(-1234.12645f);
              Assert.AreEqual("-1234.12", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234.12645f, AppendNumberOptions.None);
              Assert.AreEqual("1234.13", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234.12645f, AppendNumberOptions.PositiveSign);
              Assert.AreEqual("+1234.13", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234.12645f, AppendNumberOptions.NumberGroup);
              Assert.AreEqual("1,234.13", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234.12645f, AppendNumberOptions.PositiveSign | AppendNumberOptions.NumberGroup);
              Assert.AreEqual("+1,234.13", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(123412600f, AppendNumberOptions.PositiveSign | AppendNumberOptions.NumberGroup);
              Assert.AreEqual("+123,412,600.00", stringBuilder.ToString()); // Note: Value differs because of limited precision of floating-point.

              // If the number is too long the AppendNumber falls back to StringBuilder.Append() and uses
              // exponential notation.
              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234126000000000000000f);
              Assert.IsTrue(stringBuilder.ToString().Length > 0);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:55,代码来源:StringBuilderHelperTest.cs


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