Convert.ToDecimal Method (Single)
[ 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 single-precision floating point number to the equivalent Decimal number.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Single
A single-precision floating point number.
| Exception | Condition |
|---|---|
| OverflowException | value is greater than Decimal.MaxValue or less than Decimal.MinValue. |
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