This documentation is archived and is not being maintained.

Convert.ToDecimal Method (Object)

Converts the value of the specified object to an equivalent decimal number.

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

public static decimal ToDecimal(
	Object value


Type: System.Object
An object that implements the IConvertible interface, or null.

Return Value

Type: System.Decimal
A decimal number that is equivalent to value, or 0 (zero) if value is null.


value is not in an appropriate format for a Decimal type.


value does not implement the IConvertible interface.


The conversion is not supported.


value represents a number that is less than Decimal.MinValue or greater than Decimal.MaxValue.

The return value is the result of invoking the IConvertible.ToDecimal method of the underlying type of value.

The following example tries to convert each element in an object array to a Decimal value.

object[] values = { true, 'a', 123, 1.764e32, "9.78", "1e-02",
                    1.67e03, "A100", "1,033.67", DateTime.Now,
                    Double.MaxValue };   
decimal result;

foreach (object value in values)
   try {
      result = Convert.ToDecimal(value);
      Console.WriteLine("Converted the {0} value {1} to {2}.",
                        value.GetType().Name, value, result);
   catch (OverflowException) {
      Console.WriteLine("The {0} value {1} is out of range of the Decimal type.",
                        value.GetType().Name, value);
   catch (FormatException) {
      Console.WriteLine("The {0} value {1} is not recognized as a valid Decimal value.",
                        value.GetType().Name, value);
   catch (InvalidCastException) {
      Console.WriteLine("Conversion of the {0} value {1} to a Decimal is not supported.",
                        value.GetType().Name, value);
// The example displays the following output:
//    Converted the Boolean value True to 1.
//    Conversion of the Char value a to a Decimal is not supported.
//    Converted the Int32 value 123 to 123.
//    The Double value 1.764E+32 is out of range of the Decimal type.
//    Converted the String value 9.78 to 9.78.
//    The String value 1e-02 is not recognized as a valid Decimal value.
//    Converted the Double value 1670 to 1670.
//    The String value A100 is not recognized as a valid Decimal value.
//    Converted the String value 1,033.67 to 1033.67.
//    Conversion of the DateTime value 10/15/2008 05:40:42 PM to a Decimal is not supported.
//    The Double value 1.79769313486232E+308 is out of range of the Decimal type.      

.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.