本文整理汇总了C#中BigDecimal.ToSingle方法的典型用法代码示例。如果您正苦于以下问题:C# BigDecimal.ToSingle方法的具体用法?C# BigDecimal.ToSingle怎么用?C# BigDecimal.ToSingle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.ToSingle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToSingle
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");
}