Decimal.ToString Method (String)

Converts the numeric value of this instance to its equivalent String representation, using the specified format.

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

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



A String containing a format specification.

Return Value

A String representation of the value of this instance as specified by format.

Exception typeCondition


format is invalid.

If format is a null reference (Nothing in Visual Basic) or an empty string, the return value of this instance is formatted with the general format specifier ("G").

The return value is formatted with 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, 
    } //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