Convert.ToDecimal Method (Single)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Function ToDecimal ( _
    value As Single _
) As Decimal
public static decimal ToDecimal(
    float value
)

Parameters

  • value
    Type: System.Single
    A single-precision floating point number.

Return Value

Type: System.Decimal
A Decimal number equivalent to the value of value.

Exceptions

Exception Condition
OverflowException

value is greater than Decimal.MaxValue or less than Decimal.MinValue.

Remarks

The Decimal value returned by this method contains a maximum of 7 significant digits. If the value parameter contains more than seven significant digits, it is rounded using rounding to nearest. The following example illustrates how the Convert.ToDecimal(Single) method uses rounding to nearest to return a Decimal value with 7 significant digits.

outputBlock.Text &= Convert.ToDecimal(1.23456755E+9F) & vbCrLf   ' Displays 1234568000
outputBlock.Text &= Convert.ToDecimal(1.23456845E+9F) & vbCrLf   ' Displays 1234568000

outputBlock.Text &= Convert.ToDecimal(10.9803648F) & vbCrLf       ' Displays 10.98036 
outputBlock.Text &= Convert.ToDecimal(10.9803553F) & vbCrLf       ' Displays 10.98036
outputBlock.Text += Convert.ToDecimal(1234567500.12F) + "\n";  // Displays 1234568000
outputBlock.Text += Convert.ToDecimal(1234568500.12F) + "\n";  // Displays 1234568000

outputBlock.Text += Convert.ToDecimal(10.980365F) + "\n";      // Displays 10.98036 
outputBlock.Text += Convert.ToDecimal(10.980355F) + "\n";      // Displays 10.98036

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.