本文整理汇总了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());
}
示例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);
}