ToSingle Method (Double)

Convert.ToSingle Method (Double)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts the value of the specified double-precision floating point number to an equivalent single-precision floating point number.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Shared Function ToSingle ( _
	value As Double _
) As Single

Parameters

value
Type: System.Double
A double-precision floating point number.

Return Value

Type: System.Single
A single-precision floating point number equivalent to the value of value.
value is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36.

The following code sample illustrates the conversion of a Double to Single, using ToSingle.


Public Sub CovertDoubleFloat(ByVal doubleVal As Double)
   Dim singleVal As Single = 0

   ' Double to Single conversion cannot overflow.
   singleVal = System.Convert.ToSingle(doubleVal)
   outputBlock.Text &= String.Format("{0} as a Single is {1}", _
                             doubleVal, singleVal) & vbCrLf

   ' Conversion from Single to Double cannot overflow.
   doubleVal = System.Convert.ToDouble(singleVal)
   outputBlock.Text &= String.Format("{0} as a Double is: {1}", _
                             singleVal, doubleVal) & vbCrLf
End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft