BigInteger Explicit Conversion (Single to BigInteger)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Defines an explicit conversion of a Single object to a BigInteger value.
Namespace: System.Numerics
Assembly: System.Numerics (in System.Numerics.dll)
Syntax
'Declaration
Public Shared Narrowing Operator CType ( _
value As Single _
) As BigInteger
public static explicit operator BigInteger (
float value
)
Parameters
- value
Type: System.Single
The value to convert to a BigInteger.
Return Value
Type: System.Numerics.BigInteger
An object that contains the value of the value parameter.
Exceptions
Exception | Condition |
---|---|
OverflowException | value is Single.NaN. -or- value is Single.PositiveInfinity. -or- value is Single.NegativeInfinity. |
Remarks
Any fractional part of the value parameter is truncated before conversion.
The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger can be converted. Because the conversion from Single to BigInteger can involve truncating any fractional part of value, language compilers do not perform this conversion automatically. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.
Examples
The following example converts the individual elements in an array of Single values to BigInteger objects, and then displays the result of each conversion. Note that any fractional part of a Single value is truncated during the conversion.
Dim singles() As Single = { Single.MinValue, -1.430955172e03, 2.410970032e05,
Single.MaxValue, Single.PositiveInfinity,
Single.NegativeInfinity, Single.NaN }
Dim number As BigInteger
outputBlock.Text += String.Format("{0,37} {1,37}", "Single", "BigInteger") & vbCrLf
outputBlock.Text &= vbCrLf
For Each value As Single In singles
Try
number = CType(value, BigInteger)
outputBlock.Text += String.Format("{0,37} {1,37}", value, number) & vbCrLf
Catch e As OverflowException
outputBlock.Text += String.Format("{0,37} {1,37}", value, "OverflowException") & vbCrLf
End Try
Next
' The example displays the following output:
' Single BigInteger
'
' -3.402823E+38 -3.4028234663852885981170418348E+38
' -1430.955 -1430
' 241097 241097
' 3.402823E+38 3.4028234663852885981170418348E+38
' Infinity OverflowException
' -Infinity OverflowException
' NaN OverflowException
float[] singles = { Single.MinValue, -1.430955172e03f, 2.410970032e05f,
Single.MaxValue, Single.PositiveInfinity,
Single.NegativeInfinity, Single.NaN };
BigInteger number;
outputBlock.Text += String.Format("{0,37} {1,37}\n", "Single", "BigInteger") + "\n";
foreach (float value in singles)
{
try
{
number = (BigInteger)value;
outputBlock.Text += String.Format("{0,37} {1,37}", value, number) + "\n";
}
catch (OverflowException)
{
outputBlock.Text += String.Format("{0,37} {1,37}", value, "OverflowException") + "\n";
}
}
// The example displays the following output:
// Single BigInteger
//
// -3.402823E+38 -3.4028234663852885981170418348E+38
// -1430.955 -1430
// 241097 241097
// 3.402823E+38 3.4028234663852885981170418348E+38
// Infinity OverflowException
// -Infinity OverflowException
// NaN OverflowException
Version Information
Silverlight
Supported in: 5, 4
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.