Export (0) Print
Expand All

Decimal.ToString Method ()

Converts the numeric value of this instance to its equivalent String representation.

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

public override string ToString ()
public String ToString ()
public override function ToString () : String

Return Value

A String representing the value of this instance.

The return value is formatted with the general format specifier ("G"), and the NumberFormatInfo for the current culture.

The following code sample displays the amount of money in an account.

class PiggyBank {
    public void AddPenny() {
        MyFortune = Decimal.Add(MyFortune, .01m);
    }

    public override string ToString() {
        return MyFortune.ToString("C")+" in piggy bank";
    }

    protected decimal MyFortune;
}

class PiggyBank
{
    public void AddPenny()
    {
        myFortune = System.Decimal.Add(myFortune, 
            System.Convert.ToDecimal(0.01));
    } //AddPenny

    public String ToString()
    {
        return myFortune.ToString("C") + " in piggy bank";
    } //ToString

    protected System.Decimal myFortune;
} //PiggyBank

class PiggyBank {
    protected var MyFortune : Decimal;

    public function AddPenny() {
        MyFortune = Decimal.Add(MyFortune, 0.01);
    }

    public function ToString() : String {
        return MyFortune.ToString("C")+" in piggy bank";
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft