This documentation is archived and is not being maintained.

Decimal Narrowing Conversion (Decimal to Single)

Converts a Decimal to a single-precision floating-point number.

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

Public Shared Narrowing Operator CType ( _
	value As Decimal _
) As Single


Type: System.Decimal
The value to convert.

Return Value

Type: System.Single
A single-precision floating-point number that represents the converted Decimal.

This operation can produce round-off errors because a single-precision floating-point number has fewer significant digits than a Decimal.

This operator supports the explicit conversion of a Decimal to a Single. The syntax for such explicit conversions is language-dependent, and individual language compilers can provide different implementations and return different results. The example illustrates the different return values when you explicitly convert a Decimal value to a Single value by using C# and Visual Basic. To perform a conversion that is independent of language, you can call the ToSingle or the Convert.ToSingle(Decimal) method.

The following code example converts Decimal numbers to Single values using the explicit Decimal to Single conversion.

' Example of the explicit conversions from decimal to float and 
' decimal to double.
Module DecimalToSgl_DblDemo

    Const formatter As String = "{0,30}{1,17}{2,23}"

    ' Convert the Decimal argument to a floating point value
    ' No exceptions are thrown.
    Public Sub DecimalToSgl_Dbl(argument As Decimal)
        Dim SingleValue As Single
        Dim DoubleValue As Double

        ' Convert the argument to a Single value.
        SingleValue = CSng(argument)

        ' Convert the argument to a Double value.
        DoubleValue = CDbl(argument)

        Console.WriteLine(formatter, argument, _ 
            SingleValue, DoubleValue )
    End Sub

    Public Sub Main( )
        Console.WriteLine( formatter, "Decimal argument", _ 
            "Single", "Double" )
        Console.WriteLine( formatter, "----------------", _
            "-----", "------" )

        ' Convert decimal values and display the results.
        DecimalToSgl_Dbl(New Decimal( 123000000, 0, 0, False, 6))
        DecimalToSgl_Dbl(Decimal.MinValue )
        DecimalToSgl_Dbl(Decimal.MaxValue )
    End Sub
End Module
' The example displays the following output to the console:
'                  Decimal argument           Single                 Double
'                  ----------------            -----                 ------
'    0.0000000000000000000000000001            1E-28                  1E-28
'    0.0000000000123456789123456789     1.234568E-11   1.23456789123457E-11
'                               123              123                    123
'                        123.000000              123                    123
'               123456789.123456789     1.234568E+08       123456789.123457
'       123456789123456789123456789     1.234568E+26   1.23456789123457E+26
'    -79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
'     79228162514264337593543950335     7.922816E+28   7.92281625142643E+28

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.