Export (0) Print
Expand All

Convert.ToString Method (Decimal)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function ToString( _
   ByVal value As Decimal _
) As String
public static string ToString(
 decimal value
public: static String* ToString(
 Decimal value
public static function ToString(
   value : Decimal
) : String;


A Decimal number.

Return Value

The String equivalent of the value of value.


This implementation is identical to Decimal.ToString.


[Visual Basic, C#, C++] The following code sample illustrates the conversion of a Decimal to a String, using ToString.

[Visual Basic] 
Public Sub ConvertStringDecimal(ByVal stringVal As String)
    Dim decimalVal As Decimal = 0

        decimalVal = System.Convert.ToDecimal(stringVal)
        System.Console.WriteLine("The string as a decimal is {0}.", _
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in string-to-decimal conversion.")
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string is not formatted as a decimal.")
    Catch exception As System.ArgumentException
        System.Console.WriteLine("The string is null.")
    End Try

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

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

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


   void ConvertStringDecimal(String* stringVal)
      Decimal decimalVal = 0;

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Convert Class | Convert Members | System Namespace | Convert.ToString Overload List

© 2015 Microsoft