Convert.ToString Method (Decimal)

Converts the value of the specified Decimal number to its equivalent String representation.

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

public static string ToString (
	decimal value
)
public static String ToString (
	Decimal value
)
public static function ToString (
	value : decimal
) : String
Not applicable.

Parameters

value

A Decimal number.

Return Value

The String equivalent of the value of value.

This implementation is identical to Decimal.ToString.

The following code sample illustrates the conversion of a Decimal to a String, using ToString.

public void ConvertStringDecimal(string stringVal) {
    decimal decimalVal = 0;
    
    try {
        decimalVal = System.Convert.ToDecimal(stringVal);
        System.Console.WriteLine(
            "The string as a decimal is {0}.", decimalVal);
    } 
    catch (System.OverflowException){
        System.Console.WriteLine(
            "The conversion from string to decimal overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is not formatted as a decimal.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine(
            "The string is null.");
    }

    // Decimal to string conversion will not overflow.
    stringVal = System.Convert.ToString(decimalVal);
    System.Console.WriteLine(
        "The decimal as a string is {0}.", stringVal);
}    

public void ConvertStringDecimal(String stringVal)
{
    System.Decimal decimalVal = System.Convert.ToDecimal(0);

    try {        
        decimalVal = System.Convert.ToDecimal(stringVal);
        System.Console.WriteLine("The string as a decimal is {0}.", 
            decimalVal);
    }
    catch (System.OverflowException exp) {
        System.Console.WriteLine(
            "The conversion from string to decimal overflowed.");
    }
    catch (System.FormatException exp) {        
        System.Console.WriteLine(
            "The string is not formatted as a decimal.");
    }
    catch (System.ArgumentNullException exp) {        
        System.Console.WriteLine("The string is null.");
    }

    // Decimal to string conversion will not overflow.
    stringVal = System.Convert.ToString(decimalVal);
    System.Console.WriteLine("The decimal as a string is {0}.", stringVal);
} //ConvertStringDecimal

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: